If ninja
is not installed, you can install it using one of the following methods:
conda install -c conda-forge ninja
conda create -n linear_reg_env -y
conda activate linear_reg_env
conda install -c conda-forge cmake
conda install matplotlib
Install xtensor
and xtensor-blas
from conda-forge
:
conda install -c conda-forge xtensor xtensor-blas
conda install -c conda-forge cmake
Use CMake
and Ninja
to build the project:
mkdir build && cd build
cmake -G Ninja ..
ninja
./main
./tests/test_linear_regression
./src/visualization
-
src/main.cc
: It generates a synthetic dataset, applies linear regression using both closed-form and gradient descent methods, and outputs the results. -
src/optim.h
andsrc/optim.cc
: These files define the algorithms used in the project. TheClosedForm
class implements the closed-form solution for linear regression, while theGradientDescent
class implements the iterative gradient descent algorithm. -
src/loss.h
andsrc/loss.cc
: Defines the loss functions used to evaluate the performance of the linear regression model. TheMSELoss
class calculates the mean squared error, and theRMSELoss
class calculates the root mean squared error. -
tests/test_linear_regression.cc
: Unit tests for the linear regression model. -
src/visualization.cc
: This file contains the code for the visualization of the data and the results.