Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions docs/methods/linear_model/lasso_regularization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Lasso Regularization

It stands for Least Absolute Shrinkage and Selection Operator. It adds L1 the penalty.

L1 is the sum of the absolute value of the beta coefficients

## Parameters

| Name | Definition | Defaults | Type |
| ------------- | ------------------------------------------------------------------------------------------- | -------- | ---------|
| lambda | Constant that multiplies the L1 term, controlling regularization strength | 0.01 | `double` |


## Attributes

| Name | Definition | Shape |
| ------------ | --------------------------------------------------------- | ---------- |
| Coefficients | Estimated coefficients for the lasso regularization | n_features |

## Methods

| Name | Definition | Return value |
| ------------------------------- | ----------------------------------------------------- | ----------------- |
| `lossFunction(vector<vector<T>> x, vector<T> y)` |regularize loss function | `double` |
| `gradient(vector<vector<T>> x,vector<T> y)` | Find gradient | `vector<double>` |
| `gradientDescent(vector<vector<T>> x, vector<T> y, double alpha)` | gradient optimization algorithm | `void` |
| `fit(vector<vector<T>> x, vector<T> y,int epochs,double alpha)` | Fit linear model | `vector<double>` |
| `predict(vector<vector<T>> x)` | Predict using the linear model | `vector<T>` |
| `printCoefficients()` | Print coefficient of determination of the prediction | `void` |

## Example

```cpp
double alpha = 0.01;
std::vector<std::vector<double>> x = {{1, 2, 3}, {2, 3, 4}, {3, 4, 5}, {4, 5, 6}};
std::vector<double> y = {2, 3, 4, 5};
double lambda = 0.1;
int epochs = 1000;
RidgeRegularization<double> model(alpha);
model.fit(x, y, epochs, alpha);
model.printCoefficients();
std::vector<double> yPred;
for (int i = 0; i < x.size(); i++)
{
yPred.push_back(predict(x[i]));
}
for (int i = 0; i < y.size(); i++)
std::cout << "Actual value: " << y[i] << ", Predicted value: " << yPred[i]<< std::endl;

```
50 changes: 50 additions & 0 deletions docs/methods/linear_model/ridge_regularization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Ridge Regularization

It adds L2 as the penalty.

L2 is the sum of the square of the magnitude of beta coefficients.

## Parameters

| Name | Definition | Defaults | Type |
| ------------- | ------------------------------------------------------------------------------------------- | -------- | ---------|
| lambda | Constant that multiplies the L1 term, controlling regularization strength | 0.01 | `double` |


## Attributes

| Name | Definition | Shape |
| ------------ | --------------------------------------------------------- | ---------- |
| Coefficients | Estimated coefficients for the ridge regularization | n_features |

## Methods

| Name | Definition | Return value |
| ------------------------------- | ----------------------------------------------------- | ----------------- |
| `lossFunction(vector<T> x, double y)` |regularize loss function | `double` |
| `gradient(vector<T> x,double y)` | Find gradient | `vector<double>` |
| `gradientDescent(vector<vector<T>> x, vector<T> y, double alpha,int epochs)` | gradient optimization algorithm | `void` |
| `fit(vector<vector<T>> x, vector<T> y,int epochs,double alpha)` | Fit linear model | `vector<double>` |
| `predict(vector<T> x)` | Predict using the linear model | `double` |
| `printCoefficients()` | Print coefficient of determination of the prediction | `void` |

## Example

```cpp
double alpha = 0.01;
std::vector<std::vector<double>> x = {{1, 2, 3}, {2, 3, 4}, {3, 4, 5}, {4, 5, 6}};
std::vector<double> y = {2, 3, 4, 5};
double lambda = 0.1;
int epochs = 1000;
RidgeRegularization<double> model(alpha);
model.fit(x, y, epochs, alpha);
model.printCoefficients();
std::vector<double> yPred;
for (int i = 0; i < x.size(); i++)
{
yPred.push_back(predict(x[i]));
}
for (int i = 0; i < y.size(); i++)
std::cout << "Actual value: " << y[i] << ", Predicted value: " << yPred[i] << std::endl;

```
33 changes: 0 additions & 33 deletions docs/methods/metrics/silhouette_score.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "../../../src/slowmokit/methods/cluster/kMeans.hpp"
#include "../../src/slowmokit/methods/cluster/kMeans.hpp"
#include <bits/stdc++.h>

int main()
{
Expand Down
22 changes: 22 additions & 0 deletions examples/linear_model/lasso_regression.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// #include "../src/slowmokit/methods/linear_model/lasso_regression.hpp"

// int main()
// {
// std::vector<std::vector<double>> x = {
// {1.0, 2.0, 3.0}, {2.0, 3.0, 4.0}, {3.0, 4.0, 5.0}};
// std::vector<double> y = {1.0, 2.0, 3.0};
// double alpha = 0.01;
// double lambda = 0.1;
// int epochs = 100;

// LassoRegularization<double> model(alpha);
// model.fit(x, y, epochs, alpha);
// model.printCoefficients();

// std::vector<double> yPred = model.predict(x);
// for (int i = 0; i < y.size(); i++)
// std::cout << "Actual value: " << y[i] << ", Predicted value: " << yPred[i]
// << std::endl;

// return 0;
// }
18 changes: 18 additions & 0 deletions examples/linear_model/linear_regression.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "../../src/slowmokit/methods/linear_model/linear_regression.hpp"
#include "../../src/slowmokit/core.hpp"

int main()
{
LinearRegression<double> model;
std::vector<vector<double>> x = {{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}};
std::vector<double> y = {2, 3, 4, 5, 6};

model.fit(x, y);
model.printCoefficients();

std::vector<double> yPred = model.predict(x);
for (int i = 0; i < y.size(); i++)
cout << "Actual value: " << y[i] << ", Predicted value: " << yPred[i] << endl;

return 0;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// #include "../../../src/slowmokit/methods/linear_model/logistic_regression.hpp"
// #include "../../src/slowmokit/methods/linear_model/logistic_regression.hpp"
// #include "../../src/slowmokit/core.hpp"

// int main()
// {
Expand Down
25 changes: 25 additions & 0 deletions examples/linear_model/ridge_regression.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// #include "../src/slowmokit/methods/linear_model/ridge_regression.hpp"

// int main()
// {
// double alpha = 0.01;
// std::vector<std::vector<double>> x = {
// {1, 2, 3}, {2, 3, 4}, {3, 4, 5}, {4, 5, 6}};
// std::vector<double> y = {2, 3, 4, 5};

// double lambda = 0.1;
// int epochs = 1000;
// RidgeRegularization<double> model(alpha);
// model.fit(x, y, epochs, alpha);
// model.printCoefficients();
// std::vector<double> yPred;
// for (int i = 0; i < x.size(); i++)
// {
// yPred.push_back(predict(x[i]));
// }
// for (int i = 0; i < y.size(); i++)
// std::cout << "Actual value: " << y[i] << ", Predicted value: " << yPred[i]
// << std::endl;

// return 0;
// }
4 changes: 1 addition & 3 deletions examples/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
int main()
{
int n = 3, m = 3;
Matrix<int> mat(2, 2);

// std::cout << mat << " 2";

return 0;
}
}
17 changes: 0 additions & 17 deletions examples/methods/linear_model/linear_regression.cpp

This file was deleted.

17 changes: 0 additions & 17 deletions examples/methods/metrics/silhouette_score.cpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// #include "../../src/slowmokit/methods/metrics/accuracy.hpp"
// #include "../src/slowmokit/methods/metrics/accuracy.hpp"

// int main() {
// std::vector<int> pred = {1, 0, 1, 1, 0, 1};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// #include "../../src/slowmokit/methods/metrics/classification_report.hpp"
// #include "../src/slowmokit/methods/metrics/classification_report.hpp"

// int main()
// {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// #include "../../src/slowmokit/methods/metrics/mean_squared_error.hpp"
// #include "../src/slowmokit/methods/metrics/mean_squared_error.hpp"
// int main() {
// std::vector<double> actual = {1.0, 2.0, 3.0};
// std::vector<double> pred = {0.5, 1.5, 2.5};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// #include "../../src/slowmokit/methods/metrics/precision.hpp"
// #include "../src/slowmokit/methods/metrics/precision.hpp"
// int main()
// {
// std::vector<int> pred = {0, 1, 2, 1, 0, 2, 1, 0, 1, 2};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// #include "../../src/slowmokit/methods/metrics/recall.hpp"
// #include "../src/slowmokit/methods/metrics/recall.hpp"

// int main()
// {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// #include "../../../src/slowmokit/methods/neighbors/bernoulli_nb.hpp"
// #include "../../src/slowmokit/methods/neighbors/bernoulli_nb.hpp"
// #include "../../src/slowmokit/core.hpp"

// signed main(){
// std::vector<std::vector<int>> xTrain{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// #include "../../../src/slowmokit/methods/neighbors/gaussian_nb.hpp"
// #include "../../src/slowmokit/methods/neighbors/gaussian_nb.hpp"
// #include "../../src/slowmokit/core.hpp"

// signed main(){
// std::vector<std::vector<double>> x_train{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// #include "../../../src/slowmokit/methods/neighbors/knn.hpp"
// #include "../../src/slowmokit/methods/neighbors/knn.hpp"
// #include "../../src/slowmokit/core.hpp"

// signed main(){
// std::vector<std::vector<double>> x{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//#include "../../src/slowmokit/methods/preprocessing/label_encoder.hpp"
//#include "src/slowmokit/methods/preprocessing/label_encoder.hpp"

//int main() {
// std::vector<std::string> data = {"luffy","zoro","sanji","luffy","law","zoro"};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// #include "../../src/slowmokit/methods/preprocessing/normalization.hpp"
// #include "../src/slowmokit/methods/preprocessing/normalization.hpp"
// int main(){
// std::vector<double> values={1,2,3,4,5};
// normalize(values);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//#include "../../src/slowmokit/methods/preprocessing/one_hot_encoder.hpp"
//#include "src/slowmokit/methods/preprocessing/one_hot_encoder.hpp"

//int main() {
// std::vector<std::string> data = {"apples", "banana", "mango", "pear", "mango","apples","pear"};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// #include "../../src/slowmokit/methods/preprocessing/standardization.hpp"
// #include "../src/slowmokit/methods/preprocessing/standardization.hpp"

// int main(){
// std::vector<double> values={1,2,3,4,5};
Expand Down
7 changes: 0 additions & 7 deletions src/slowmokit.cpp

This file was deleted.

16 changes: 0 additions & 16 deletions src/slowmokit/CMakeLists.txt

This file was deleted.

3 changes: 3 additions & 0 deletions src/slowmokit/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
// pre-requisites of the library
#include "prereqs.hpp"

// standard model class
#include "models/model.hpp"

#endif // SLOWMOKIT_CORE_HPP
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file ducks/matrix/matrix_main.cpp
* @file ducks/matrix/matrix.cpp
*
* Implementation of the main methods of Matrix
* Implementation of the matrix main program
*/

#include "matrix.hpp"
Expand Down
Loading