Skip to content

obluda2173/ft_linear_regression_cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README — Linear Regression (Org) — Erik An

Summary

Short: simple linear-regression project (C++) that trains on data/data.csv, saves model to data/model.json, and has a small predictor and plotting script. Designed for learning: gradient descent implemented by you, no cheating with np.polyfit for the final model.

Repo layout

.
├── data/
│ ├── data.csv # dataset (km,price)
│ └── model.json # saved model (theta0, theta1)
├── src/
│ ├── cpp/
│ │ ├── BGD.hpp
│ │ ├── BGD.cpp
│ │ ├── train.cpp
│ │ ├── predict.cpp
│ │ ├── precision.cpp
│ │ └── model_io.cpp
│ └── python/
│ └── graph.py
├── bin/ # build output (created by Makefile)
└── Makefile

Requirements

g++ (C++17), make

Python 3 (for plotting script), matplotlib, pandas, numpy (optional)

Build & main Makefile targets

Use the provided Makefile from project root.

build everything (compile train, predict, precision)

make

rebuild from scratch

make re

build and run trainind along with predictor

make run

build and run training (creates data/model.json)

make train

build and run prediction

make predict

build and run precision (computes MSE and RMSE)

make precision

create graphs (Python)

make graph

clean build artifacts and model

make clean

Typical workflow

Inspect data:

python3 src/python/graph.py (prints table / checks)

Train model:

make train

writes data/model.json (atomic save)

Predict:

make predict and enter a mileage when prompted

Evaluate:

make precision — prints MSE, RMSE

Visualize:

make graph — runs src/python/graph.py to plot scatter + fitted line (I should add learning curve)

Model format (data/model.json)

Saved as JSON with double precision. Minimal example:

{
    "theta0": 123.45678901234567,
    "theta1": -0.0123456789012345,
}

How MSE/RMSE relate to units

MSE units are squared (dollars^2). RMSE = sqrt(MSE) returns dollars and is easier to interpret.

Example: MSE = 500000 ⇒ RMSE ≈ 707 dollars. Compare RMSE to mean price to judge reasonable error.

Graphs from bonus part

Plotted records of the mileage/cost along with best fit line calculated in train.cpp:

Optional learning rate graph (epoch / Root Mean Square Error):

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors