openGPMP
Open Source Mathematics Package
Functions
regression.cpp File Reference
#include <iostream>
#include <openGPMP/ml/linreg.hpp>
#include <stdio.h>

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

◆ main()

int main ( void  )

Definition at line 14 of file regression.cpp.

14  {
15  const char *test_file = "../../data/school_scores.csv";
16  freopen(test_file, "r", stdin);
17  // declare Regression class object
19 
20  // gpmp::DataTable dt;
21  // dt.csv_read(test_file, drop_col_names=true);
22  //
23 
24  // int n = reg.num_rows(test_file);
25  printf("LINEAR REGRESSION EXAMPLE ON YEAR/GPA DATA IN "
26  "MATHEMATICS\n");
27 
28  // printf("Number of rows in data set: %d\n", n);
29  // Calling function takeInput to take input of n pairs
30  reg.get_input(test_file);
31 
32  // Printing the best fitting line
33  reg.best_fit();
34 
35  /* CALCULATING PREDICTIONS */
36  int v1 = 1995;
37  double v1_v = reg.predict(v1);
38  double v1_e = reg.error_in(v1);
39  printf("Predicted value at %d = %f\n", v1, v1_v);
40  printf("Error value at %d = %f\n\n", v1, v1_e);
41 
42  int v2 = 1997;
43  double v2_v = reg.predict(v2);
44  double v2_e = reg.error_in(v2);
45  printf("Predicted value at %d = %f\n", v2, v2_v);
46  printf("Error value at %d = %f\n\n", v2, v2_e);
47 
48  int v3 = 1999;
49  double v3_v = reg.predict(v3);
50  double v3_e = reg.error_in(v3);
51  printf("Predicted value at %d = %f\n", v3, v3_v);
52  printf("Error value at %d = %f\n\n", v3, v3_e);
53 
54  int v4 = 2001;
55  double v4_v = reg.predict(v4);
56  double v4_e = reg.error_in(v4);
57  printf("Predicted value at %d = %f\n", v4, v4_v);
58  printf("Error value at %d = %f\n\n", v4, v4_e);
59 
60  int v5 = 2003;
61  double v5_v = reg.predict(v5);
62  double v5_e = reg.error_in(v5);
63  printf("Predicted value at %d = %f\n", v5, v5_v);
64  printf("Error value at %d = %f\n\n", v5, v5_e);
65 
66  int v6 = 2005;
67  double v6_v = reg.predict(v6);
68  double v6_e = reg.error_in(v6);
69  printf("Predicted value at %d = %f\n", v6, v6_v);
70  printf("Error value at %d = %f\n\n", v6, v6_e);
71 
72  int v7 = 2006;
73  double v7_v = reg.predict(v7);
74  double v7_e = reg.error_in(v7);
75  printf("Predicted value at %d = %f\n", v7, v7_v);
76  printf("Error value at %d = %f\n\n", v7, v7_e);
77 
78  int v8 = 2007;
79  double v8_v = reg.predict(v8);
80  double v8_e = reg.error_in(v8);
81  printf("Predicted value at %d = %f\n", v8, v8_v);
82  printf("Error value at %d = %f\n\n", v8, v8_e);
83 
84  int v10 = 2016;
85  double v10_v = reg.predict(v10);
86  double v10_e = reg.error_in(v10);
87  printf("Predicted value at %d = %f\n", v10, v10_v);
88  printf("Error value at %d = %f\n\n", v10, v10_e);
89 
90  int v11 = 2017;
91  double v11_v = reg.predict(v11);
92  double v11_e = reg.error_in(v11);
93  printf("Predicted value at %d = %f\n", v11, v11_v);
94  printf("Error value at %d = %f\n\n", v11, v11_e);
95 }
void best_fit()
Calculates and displays the best fitting line based on training data.
Definition: linreg.cpp:110
long double error_in(long double num)
Calculates the error (residual) for a given independent variable value.
Definition: linreg.cpp:373
long double predict(long double _x) const
Predict a value based on the input.
Definition: linreg.cpp:356
void get_input(const std::vector< long double > &x_data, const std::vector< long double > &y_data)
Sets the input data for the LinearRegression class from two vectors.
Definition: linreg.cpp:157

References gpmp::ml::LinearRegression::best_fit(), gpmp::ml::LinearRegression::error_in(), gpmp::ml::LinearRegression::get_input(), and gpmp::ml::LinearRegression::predict().