An open API service indexing awesome lists of open source software.

https://github.com/jman-9/linear-regression-practice

Practice of Linear Regression
https://github.com/jman-9/linear-regression-practice

holdout linear-equations linear-regression linear-system platform-independent ridge-regression system-of-linear-equations

Last synced: 22 days ago
JSON representation

Practice of Linear Regression

Awesome Lists containing this project

README

          

# Practice of Linear Regression

# Objectives
- implementing a solution of linear regression problem for C++
- platform independent
- reusable

# Needs
- ~~partial derivative~~
- ~~system of linear equations~~
- ~~linear least squares method~~
- ~~regularization~~
- ~~cross-validation - holdout method~~

# Achieved
- system of linear equations
- linear least squares method
- ridge regression
- cross-validation
- platform independent source codes (but nowhere any meta-build recipes, only included Visual Studio 2019 projects)
- reusable modules (maybe not used...)

# Usage of linear_system
## Code
```C++
linear_system ls;

linear_system::equation eq1{2, 3, 2};
linear_system::equation eq2{5, 4, 1};
linear_system::solution sol = ls.solve(eq1, eq2);
printf("---------\n");
printf("problem :\n");
printf("%dx + %dy + %d = 0\n", 2, 3, 2);
printf("%dx + %dy + %d = 0\n", 5, 4, 1);
printf("solution :\n");
printf("x=%d/%d, y=%d/%d\n", sol.x.num, sol.x.den, sol.y.num, sol.y.den );
printf("---------\n");

equation_matrix mat(2, 3);
mat[0][0] = 2;
mat[0][1] = 3;
mat[0][2] = 2;
mat[1][0] = 5;
mat[1][1] = 4;
mat[1][2] = 1;
linear_system::solution_vector s1 = ls.solve(mat);
printf("---------\n");
printf("problem :\n");
for(size_t i=0; i= pv.size()) break;
printf(", ");
}
printf("\n");
printf("---------\n");
```
## Result
```
---------
residuals :
no. 1 - y:8.700000, x1:0.500000
no. 2 - y:7.500000, x1:0.800000
no. 3 - y:7.100000, x1:1.100000
no. 4 - y:6.800000, x1:1.500000
parameters :
w0:9.283562, w1:-1.803653
---------
```


# Usage of ridge_regression
## Code
```C++
ridge_regression rr;
linear_least_squares::residual_list bhd;
linear_least_squares::parameter_vector pv;

CSVReader reader("../data/BostonHousing.csv");
for (CSVRow& row: reader)
{
bhd.push_back({});
bhd.back().y = row["medv"].get();

for(size_t i=0; i());
}
}

auto colnames = reader.get_col_names();
colnames.back() = "bias";

printf("=========\n");
printf("solving Boston Housing Dataset\n");

pv = rr.solve(bhd, 0.0);
printf("---------\n");
printf("parameters (not regularized) :\n");
printf("%s:%lf", colnames[0].c_str(), pv[0]);
for(size_t i=1; i