From 0690a140ecfbe55583186169577aab3b2cd16103 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Fri, 26 Jun 2020 09:03:20 -0400 Subject: [PATCH 1/4] move OLS regressor to machine learning folder --- .../ordinary_least_squares_regressor.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {numerical_methods => machine_learning}/ordinary_least_squares_regressor.cpp (100%) diff --git a/numerical_methods/ordinary_least_squares_regressor.cpp b/machine_learning/ordinary_least_squares_regressor.cpp similarity index 100% rename from numerical_methods/ordinary_least_squares_regressor.cpp rename to machine_learning/ordinary_least_squares_regressor.cpp From dcd0d6b47864468cd9645e22e206e5b59bea4c6f Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Fri, 26 Jun 2020 13:04:18 +0000 Subject: [PATCH 2/4] updating DIRECTORY.md --- DIRECTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 679e6f7d8..d678276bc 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -98,6 +98,7 @@ * [Adaline Learning](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/machine_learning/adaline_learning.cpp) * [Kohonen Som Topology](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/machine_learning/kohonen_som_topology.cpp) * [Kohonen Som Trace](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/machine_learning/kohonen_som_trace.cpp) + * [Ordinary Least Squares Regressor](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/machine_learning/ordinary_least_squares_regressor.cpp) ## Math * [Armstrong Number](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/armstrong_number.cpp) @@ -145,7 +146,6 @@ * [Ode Forward Euler](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/ode_forward_euler.cpp) * [Ode Midpoint Euler](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/ode_midpoint_euler.cpp) * [Ode Semi Implicit Euler](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/ode_semi_implicit_euler.cpp) - * [Ordinary Least Squares Regressor](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/ordinary_least_squares_regressor.cpp) * [Qr Decompose](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/qr_decompose.h) * [Qr Decomposition](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/qr_decomposition.cpp) * [Qr Eigen Values](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/qr_eigen_values.cpp) From 052c3fbca87802cc8ab95f5deb08bd94badab4fa Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Fri, 26 Jun 2020 10:37:56 -0400 Subject: [PATCH 3/4] use better test function names to avoid conflict --- machine_learning/ordinary_least_squares_regressor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/machine_learning/ordinary_least_squares_regressor.cpp b/machine_learning/ordinary_least_squares_regressor.cpp index dcbbcf8c7..54d100300 100644 --- a/machine_learning/ordinary_least_squares_regressor.cpp +++ b/machine_learning/ordinary_least_squares_regressor.cpp @@ -355,7 +355,7 @@ std::vector predict_OLS_regressor(std::vector> const &X, } /** Self test checks */ -void test() { +void ols_test() { int F = 3, N = 5; /* test function = x^2 -5 */ @@ -408,7 +408,7 @@ void test() { * main function */ int main() { - test(); + ols_test(); size_t N, F; From b9c1f6bf363aa6e34fcaa664adafef3158ce7841 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Fri, 26 Jun 2020 10:53:42 -0400 Subject: [PATCH 4/4] use better test data variable names to avoid conflict --- machine_learning/ordinary_least_squares_regressor.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/machine_learning/ordinary_least_squares_regressor.cpp b/machine_learning/ordinary_least_squares_regressor.cpp index 54d100300..896504e20 100644 --- a/machine_learning/ordinary_least_squares_regressor.cpp +++ b/machine_learning/ordinary_least_squares_regressor.cpp @@ -368,12 +368,12 @@ void ols_test() { // perform regression modelling std::vector beta1 = fit_OLS_regressor(data1, Y1); // create test data set with same features = x, x^2, x^3 - std::vector> test1( + std::vector> test_data1( {{-2, 4, -8}, {2, 4, 8}, {-10, 100, -1000}, {10, 100, 1000}}); // expected regression outputs std::vector expected1({-1, -1, 95, 95}); // predicted regression outputs - std::vector out1 = predict_OLS_regressor(test1, beta1); + std::vector out1 = predict_OLS_regressor(test_data1, beta1); // compare predicted results are within +-0.01 limit of expected for (size_t rows = 0; rows < out1.size(); rows++) assert(std::abs(out1[rows] - expected1[rows]) < 0.01); @@ -389,12 +389,12 @@ void ols_test() { // perform regression modelling std::vector beta2 = fit_OLS_regressor(data2, Y2); // create test data set with same features = x, x^2, x^3 - std::vector> test2( + std::vector> test_data2( {{-2, 4, -8}, {2, 4, 8}, {-10, 100, -1000}, {10, 100, 1000}}); // expected regression outputs std::vector expected2({-104, -88, -1000, 1000}); // predicted regression outputs - std::vector out2 = predict_OLS_regressor(test2, beta2); + std::vector out2 = predict_OLS_regressor(test_data2, beta2); // compare predicted results are within +-0.01 limit of expected for (size_t rows = 0; rows < out2.size(); rows++) assert(std::abs(out2[rows] - expected2[rows]) < 0.01);