openGPMP
Open Source Mathematics Package
Public Member Functions | Public Attributes | List of all members
gpmp::ml::LinearRegression Class Reference

#include <linreg.hpp>

Public Member Functions

 LinearRegression ()
 Constructor for LinearRegression. More...
 
void calculate_coeffecient ()
 Calculates the coefficient/slope of the best fitting line. More...
 
void calculate_constant ()
 Calculate the constant term of the best fitting line. More...
 
int64_t data_size ()
 Get the number of entries (xi, yi) in the data set. More...
 
long double return_coeffecient ()
 Get the coefficient/slope of the best fitting line. More...
 
long double return_constant ()
 Get the constant term of the best fitting line. More...
 
void best_fit ()
 Calculates and displays the best fitting line based on training data. More...
 
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. More...
 
void get_input (const gpmp::core::DataTableStr &data, const std::vector< std::string > &columns)
 Takes input data in the form of a DataTable and prepares it for regression analysis. More...
 
void get_input (const char *file)
 Takes input data from a file and prepares it for regression analysis. More...
 
void split_data (double test_size, unsigned int seed, bool shuffle)
 Splits the data into training and testing sets. More...
 
void show_data ()
 Display the data set. More...
 
long double predict (long double _x) const
 Predict a value based on the input. More...
 
long double predict (long double _x, const std::vector< long double > &x_data)
 Predict a value based on the input. More...
 
long double error_in (long double num)
 Calculates the error (residual) for a given independent variable value. More...
 
long double error_in (long double num, const std::vector< long double > &x_data, const std::vector< long double > &y_data)
 Calculates the error (residual) for a given independent variable value using a dataset. More...
 
long double error_square ()
 Calculates the sum of squared errors for the entire dataset. More...
 
long double mse (const std::vector< long double > &x_data, const std::vector< long double > &y_data) const
 Calculates the Mean Squared Error (MSE) for a dataset. More...
 
long double r_sqrd (const std::vector< long double > &x_data, const std::vector< long double > &y_data) const
 Calculate the coefficient of determination (R-squared). More...
 
int64_t num_rows (const char *input)
 Calculate the number of rows in a file. More...
 

Public Attributes

std::vector< long double > x
 
std::vector< long double > y
 
long double coeff
 
long double constant
 
long double sum_xy
 
long double sum_x
 
long double sum_y
 
long double sum_x_square
 
long double sum_y_square
 
std::vector< long double > x_train
 
std::vector< long double > y_train
 
std::vector< long double > x_test
 
std::vector< long double > y_test
 

Detailed Description

Examples
linreg.cpp.

Definition at line 53 of file linreg.hpp.

Constructor & Destructor Documentation

◆ LinearRegression()

gpmp::ml::LinearRegression::LinearRegression ( )

Constructor for LinearRegression.

Definition at line 54 of file linreg.cpp.

54  {
55  coeff = 0;
56  constant = 0;
57  sum_y = 0;
58  sum_y_square = 0;
59  sum_x_square = 0;
60  sum_x = 0;
61  sum_xy = 0;
62 }
long double sum_x_square
Definition: linreg.hpp:70
long double sum_y_square
Definition: linreg.hpp:72

References coeff, constant, sum_x, sum_x_square, sum_xy, sum_y, and sum_y_square.

Member Function Documentation

◆ best_fit()

void gpmp::ml::LinearRegression::best_fit ( )

Calculates and displays the best fitting line based on training data.

This function calculates the best fitting line using the training data and displays the result. If training data is empty, it will also handle the case when the coefficients and constants are not calculated.

Examples
linreg.cpp.

Definition at line 110 of file linreg.cpp.

110  {
111  if (x_train.empty() || y_train.empty()) {
112  // Check if training data is empty
113  _log_.log(WARNING, "Training data is empty.");
114 
115  if (fabs(coeff - 0.0f) < std::numeric_limits<double>::epsilon() &&
116  fabs(constant - 0.0f) < std::numeric_limits<double>::epsilon()) {
117  // If coefficients are not calculated, calculate them
120  }
121  // Display the best fitting line equation
122  _log_.log(INFO,
123  "Best fitting line : y = " + std::to_string(coeff) + "x + " +
124  std::to_string(constant));
125  return;
126  }
127 
128  // Calculate the coefficients using the training data
129  long double N = x_train.size();
130  long double sum_xy_train = 0;
131  long double sum_x_train = 0;
132  long double sum_y_train = 0;
133  long double sum_x_square_train = 0;
134 
135  for (size_t i = 0; i < N; i++) {
136  // Calculate sums for the training data
137  sum_xy_train += x_train[i] * y_train[i];
138  sum_x_train += x_train[i];
139  sum_y_train += y_train[i];
140  sum_x_square_train += x_train[i] * x_train[i];
141  }
142 
143  long double numerator = (N * sum_xy_train - sum_x_train * sum_y_train);
144  long double denominator =
145  (N * sum_x_square_train - sum_x_train * sum_x_train);
146 
147  // Calculate the coefficients of the best fitting line
148  coeff = numerator / denominator;
149  constant = (sum_y_train - coeff * sum_x_train) / N;
150  // Display the best fitting line equation
151  _log_.log(INFO,
152  "Best fitting line : y = " + std::to_string(coeff) + "x + " +
153  std::to_string(constant));
154 }
const int N
void log(LogLevel level, const std::string &message)
Logs a message with the specified log level.
Definition: utils.cpp:77
std::vector< long double > y_train
Definition: linreg.hpp:76
void calculate_coeffecient()
Calculates the coefficient/slope of the best fitting line.
Definition: linreg.cpp:66
std::vector< long double > x_train
Definition: linreg.hpp:74
void calculate_constant()
Calculate the constant term of the best fitting line.
Definition: linreg.cpp:80
static gpmp::core::Logger _log_
Definition: linreg.cpp:48
@ INFO
Definition: utils.hpp:48
@ WARNING
Definition: utils.hpp:48

References _log_, INFO, gpmp::core::Logger::log(), N, and WARNING.

Referenced by main(), and test_train().

◆ calculate_coeffecient()

void gpmp::ml::LinearRegression::calculate_coeffecient ( )

Calculates the coefficient/slope of the best fitting line.

This function calculates the coefficient of the linear regression model by analyzing the dataset.

Definition at line 66 of file linreg.cpp.

66  {
67  // get number of datapoints
68  long double N = x.size();
69  // calculate numerator and denominator
70  long double numerator = (N * sum_xy - sum_x * sum_y);
71  long double denominator = (N * sum_x_square - sum_x * sum_x);
72  // calculate the coeffecient
73  coeff = numerator / denominator;
74 }
std::vector< long double > x
Definition: linreg.hpp:56

References N.

◆ calculate_constant()

void gpmp::ml::LinearRegression::calculate_constant ( )

Calculate the constant term of the best fitting line.

Definition at line 80 of file linreg.cpp.

80  {
81  long double N = x.size();
82  long double numerator = (sum_y * sum_x_square - sum_x * sum_xy);
83  long double denominator = (N * sum_x_square - sum_x * sum_x);
84  // calculate constant
85  constant = numerator / denominator;
86 }

References N.

◆ data_size()

int64_t gpmp::ml::LinearRegression::data_size ( )

Get the number of entries (xi, yi) in the data set.

Returns
Number of data entries.

Definition at line 89 of file linreg.cpp.

89  {
90  return x.size();
91 }

◆ error_in() [1/2]

long double gpmp::ml::LinearRegression::error_in ( long double  num)

Calculates the error (residual) for a given independent variable value.

This function computes the difference between the actual dependent variable value (y) and the predicted value based on the linear regression model for a specified independent variable (x).

Parameters
numThe independent variable value for which the error is calculated.
Returns
The error (residual) between the actual and predicted values.
Examples
linreg.cpp.

Definition at line 373 of file linreg.cpp.

373  {
374  for (int64_t i = 0; uint64_t(i) < x.size(); i++) {
375  if (fabs(num - x[i]) < std::numeric_limits<double>::epsilon()) {
376  return (y[i] - predict(x[i]));
377  }
378  }
379  return 0;
380 }
long double predict(long double _x) const
Predict a value based on the input.
Definition: linreg.cpp:356
std::vector< long double > y
Definition: linreg.hpp:58

Referenced by main(), and test_train().

◆ error_in() [2/2]

long double gpmp::ml::LinearRegression::error_in ( long double  num,
const std::vector< long double > &  x_data,
const std::vector< long double > &  y_data 
)

Calculates the error (residual) for a given independent variable value using a dataset.

This function computes the difference between the actual dependent variable value (y) and the predicted value based on the linear regression model for a specified independent variable (x).

Parameters
numThe independent variable value for which the error is calculated.
x_dataThe vector of independent variable values.
y_dataThe vector of actual dependent variable values.
Returns
The error (residual) between the actual and predicted values.

Definition at line 384 of file linreg.cpp.

386  {
387  long double prediction = predict(num, x_data);
388  // Find the corresponding y value for the input x
389  for (size_t i = 0; i < x_data.size(); i++) {
390  if (fabs(num - x_data[i]) < std::numeric_limits<double>::epsilon()) {
391  return y_data[i] - prediction;
392  }
393  }
394  return 0;
395 }

◆ error_square()

long double gpmp::ml::LinearRegression::error_square ( )

Calculates the sum of squared errors for the entire dataset.

This function computes the sum of squared differences between the actual dependent variable values (y) and the predicted values based on the linear regression model for all data points.

Returns
The sum of squared errors for the dataset.

Definition at line 398 of file linreg.cpp.

398  {
399  long double ans = 0;
400 
401  // Iterate through each data point
402  for (int64_t i = 0; uint64_t(i) < x.size(); i++) {
403  // Calculate the square of the error (difference between predicted and
404  // actual values)
405  ans += ((predict(x[i]) - y[i]) * (predict(x[i]) - y[i]));
406  }
407  return ans; // Return the sum of squared errors
408 }

◆ get_input() [1/3]

void gpmp::ml::LinearRegression::get_input ( const char *  file)

Takes input data from a file and prepares it for regression analysis.

Parameters
fileThe name of the file containing the data.

Definition at line 253 of file linreg.cpp.

253  {
254  int n = num_rows(file);
255  for (int64_t i = 0; i < n; i++) {
256  /*
257  * In a csv file, all the values of xi and yi are separated by
258  * commas
259  */
260  char comma;
261  long double xi;
262  long double yi;
263  std::cin >> xi >> comma >> yi;
264  // Update sum of (x * y)
265  sum_xy += xi * yi;
266  // Update sum of x and y
267  sum_x += xi;
268  sum_y += yi;
269  // Update sum of x squares and y squares
270  sum_x_square += xi * xi;
271  sum_y_square += yi * yi;
272  // Append x and y values to x and y vectors
273  x.push_back(xi);
274  y.push_back(yi);
275  }
276 }
int64_t num_rows(const char *input)
Calculate the number of rows in a file.
Definition: linreg.cpp:474

◆ get_input() [2/3]

void gpmp::ml::LinearRegression::get_input ( const gpmp::core::DataTableStr data,
const std::vector< std::string > &  columns 
)

Takes input data in the form of a DataTable and prepares it for regression analysis.

Parameters
dataThe DataTable containing the data.
columnsThe column names for the independent and dependent variables.

Definition at line 192 of file linreg.cpp.

194  {
195  // Clear any existing data from x and y vectors
196  x.clear();
197  y.clear();
198  sum_xy = 0;
199  sum_x = 0;
200  sum_y = 0;
201  sum_x_square = 0;
202  sum_y_square = 0;
203 
204  // Ensure that columns is not empty and has at least 2 elements
205  if (columns.size() < 2) {
206  _log_.log(ERROR, "Input vectors must have at least 2 column names.");
207  return;
208  }
209 
210  // Find the column indices for the specified column names
211  std::vector<size_t> column_indices;
212  for (const auto &column_name : columns) {
213  bool found = false;
214  for (size_t i = 0; i < data.first.size(); ++i) {
215  if (data.first[i] == column_name) {
216  column_indices.push_back(i);
217  found = true;
218  break;
219  }
220  }
221  if (!found) {
222  _log_.log(ERROR,
223  "Column '" + column_name +
224  "' not found in DataTableStr.");
225  return;
226  }
227  }
228 
229  for (const auto &row : data.second) {
230  try {
231  long double xi = std::stold(row[column_indices[0]]);
232  long double yi = std::stold(row[column_indices[1]]);
233  // Append x and y values to x and y vectors
234  x.push_back(xi);
235  y.push_back(yi);
236  // Update sum of (x * y)
237  sum_xy += xi * yi;
238  // Update sum of x and y
239  sum_x += xi;
240  sum_y += yi;
241  // Update sum of x squares and y squares
242  sum_x_square += xi * xi;
243  sum_y_square += yi * yi;
244  } catch (const std::exception &e) {
245  // Handle parsing errors here
246  _log_.log(ERROR, "Error parsing data: " + std::string(e.what()));
247  continue;
248  }
249  }
250 }
@ ERROR
Definition: utils.hpp:48

References _log_, ERROR, and gpmp::core::Logger::log().

◆ get_input() [3/3]

void gpmp::ml::LinearRegression::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.

This function accepts vectors of independent and dependent variable values and initializes the class variables.

Parameters
x_dataThe vector of independent variable values.
y_dataThe vector of dependent variable values.
Examples
linreg.cpp.

Definition at line 157 of file linreg.cpp.

159  {
160  // Clear existing data from x and y vectors
161  x.clear();
162  y.clear();
163  // Initialize LinearRegression class variables
164  sum_xy = 0; /* Set x*y sum */
165  sum_x = 0; /* Set sum of x */
166  sum_y = 0; /* Set sum of y */
167  sum_x_square = 0; /* Set sum of x squares */
168  sum_y_square = 0; /* Set sum of y squares */
169 
170  if (x_data.size() != y_data.size()) {
171  // Check if input vectors have the same size
172  _log_.log(ERROR, "Input vectors must have the same size");
173  return;
174  }
175 
176  for (size_t i = 0; i < x_data.size(); i++) {
177  // Append x and y values to x and y vectors
178  x.push_back(x_data[i]);
179  y.push_back(y_data[i]);
180  // Update sum of (x * y)
181  sum_xy += x_data[i] * y_data[i];
182  // Update sum of x and y
183  sum_x += x_data[i];
184  sum_y += y_data[i];
185  // Update sum of x squares and y squares
186  sum_x_square += x_data[i] * x_data[i];
187  sum_y_square += y_data[i] * y_data[i];
188  }
189 }

References _log_, ERROR, and gpmp::core::Logger::log().

Referenced by main(), and test_train().

◆ mse()

long double gpmp::ml::LinearRegression::mse ( const std::vector< long double > &  x_data,
const std::vector< long double > &  y_data 
) const

Calculates the Mean Squared Error (MSE) for a dataset.

The Mean Squared Error is a measure of the average squared differences between the actual dependent variable values and the predicted values based on the linear regression model.

Parameters
x_dataThe vector of independent variable values.
y_dataThe vector of actual dependent variable values.
Returns
The Mean Squared Error for the dataset. Returns -1 if input vectors have different sizes.
Examples
linreg.cpp.

Definition at line 412 of file linreg.cpp.

413  {
414  // Check if input vectors have the same size
415  if (x_data.size() != y_data.size()) {
416  return -1; // Return an error value
417  }
418 
419  long double mse = 0.0;
420  int64_t n = x_data.size();
421 
422  // Iterate through each data point
423  for (int64_t i = 0; i < n; i++) {
424  // Calculate the predicted value using the linear regression model
425  long double predicted = predict(x_data[i]);
426  // Calculate the error (difference between predicted and actual values)
427  long double error = predicted - y_data[i];
428  // Accumulate the squared error
429  mse += error * error;
430  }
431 
432  // Calculate the Mean Squared Error by dividing the accumulated squared
433  // error by the number of data points
434  return mse / static_cast<long double>(n);
435 }
long double mse(const std::vector< long double > &x_data, const std::vector< long double > &y_data) const
Calculates the Mean Squared Error (MSE) for a dataset.
Definition: linreg.cpp:412

Referenced by test_train().

◆ num_rows()

int64_t gpmp::ml::LinearRegression::num_rows ( const char *  input)

Calculate the number of rows in a file.

Parameters
inputPath to the input file.
Returns
Number of rows in the file.

Definition at line 474 of file linreg.cpp.

474  {
475  int64_t num = 0;
476  std::string row;
477 
478  // create input file stream
479  std::ifstream file(input);
480 
481  while (getline(file, row)) {
482  num++;
483  }
484 
485  return num;
486 }

◆ predict() [1/2]

long double gpmp::ml::LinearRegression::predict ( long double  _x) const

Predict a value based on the input.

Parameters
xInput value.
Returns
Predicted value.
Examples
linreg.cpp.

Definition at line 356 of file linreg.cpp.

356  {
357  return coeff * _x + constant;
358 }

Referenced by main(), and test_train().

◆ predict() [2/2]

long double gpmp::ml::LinearRegression::predict ( long double  _x,
const std::vector< long double > &  x_data 
)

Predict a value based on the input.

Parameters
xInput value.
x_dataX value data.
Returns
Predicted value.

Definition at line 362 of file linreg.cpp.

363  {
364  // Calculate the coefficient if not already calculated
365  long double _coeff = return_coeffecient();
366  // Calculate the constant if not already calculated
367  long double _constant = return_constant();
368  // TODO FIXME unused variable
369  return _coeff * _x + _constant + x_data[0];
370 }
long double return_coeffecient()
Get the coefficient/slope of the best fitting line.
Definition: linreg.cpp:94
long double return_constant()
Get the constant term of the best fitting line.
Definition: linreg.cpp:102

◆ r_sqrd()

long double gpmp::ml::LinearRegression::r_sqrd ( const std::vector< long double > &  x_data,
const std::vector< long double > &  y_data 
) const

Calculate the coefficient of determination (R-squared).

The coefficient of determination, often referred to as R-squared, is a statistical measure that represents the proportion of the variance in the dependent variable (Y) that is predictable from the independent variable (X). It quantifies the goodness of fit of the linear regression model to the data.

This function calculates the R-squared value for a linear regression model using the provided dataset of independent variable values (x_data) and dependent variable values (y_data).

Parameters
x_dataA vector of independent variable values.
y_dataA vector of corresponding dependent variable values.
Returns
The R-squared value, which is a number between 0 and 1. A higher R-squared value indicates a better fit of the model to the data.
Note
The input vectors (x_data and y_data) must have the same size.
An R-squared value of -1 is returned as an error indicator when the input vectors have different sizes.
The function uses the linear regression model's predict() method to make predictions for the independent variable values.
Examples
linreg.cpp.

Definition at line 438 of file linreg.cpp.

440  {
441  // Check if input vectors have the same size
442  if (x_data.size() != y_data.size()) {
443  _log_.log(ERROR, "Input vectors must have the same size.");
444  return -1; // Return an error value
445  }
446 
447  long double total_sum_of_squares = 0.0;
448  long double sum_of_squared_errors = 0.0;
449  int64_t n = x_data.size();
450 
451  long double y_mean = 0.0;
452  for (int64_t i = 0; i < n; i++) {
453  // Calculate the mean of the dependent variable (Y)
454  y_mean += y_data[i];
455  }
456  y_mean /= static_cast<long double>(n);
457 
458  // Iterate through each data point
459  for (int64_t i = 0; i < n; i++) {
460  // Calculate the predicted value using the linear regression model
461  long double predicted = predict(x_data[i]);
462  // Calculate the error (difference between predicted and actual values)
463  long double error = predicted - y_data[i];
464  // Calculate the total sum of squares and sum of squared errors
465  total_sum_of_squares += (y_data[i] - y_mean) * (y_data[i] - y_mean);
466  sum_of_squared_errors += error * error;
467  }
468 
469  // Calculate the R-squared value using the formula 1 - (SSE / SST)
470  return 1.0 - (sum_of_squared_errors / total_sum_of_squares);
471 }

References _log_, ERROR, and gpmp::core::Logger::log().

Referenced by test_train().

◆ return_coeffecient()

long double gpmp::ml::LinearRegression::return_coeffecient ( )

Get the coefficient/slope of the best fitting line.

Returns
Coefficient/slope.

Definition at line 94 of file linreg.cpp.

94  {
95  if (fabs(coeff - 0.0f) < std::numeric_limits<double>::epsilon()) {
97  }
98  return coeff;
99 }

◆ return_constant()

long double gpmp::ml::LinearRegression::return_constant ( )

Get the constant term of the best fitting line.

Returns
Constant term.

Definition at line 102 of file linreg.cpp.

102  {
103  if (fabs(constant - 0.0f) < std::numeric_limits<double>::epsilon()) {
105  }
106  return constant;
107 }

◆ show_data()

void gpmp::ml::LinearRegression::show_data ( )

Display the data set.

Definition at line 337 of file linreg.cpp.

337  {
338  for (int64_t i = 0; i < 62; i++) {
339  printf("_");
340  }
341  printf("\n\n");
342  printf("|%15s%5s %15s%5s%20s\n", "X", "", "Y", "", "|");
343 
344  // Display each data point in the dataset
345  for (int64_t i = 0; uint64_t(i) < x.size(); i++) {
346  printf("|%20Lf %20Lf%20s\n", x[i], y[i], "|");
347  }
348 
349  for (int64_t i = 0; i < 62; i++) {
350  printf("_");
351  }
352  printf("\n");
353 }

◆ split_data()

void gpmp::ml::LinearRegression::split_data ( double  test_size,
unsigned int  seed,
bool  shuffle 
)

Splits the data into training and testing sets.

This function splits the dataset into training and testing sets based on the specified test size and random seed.

Parameters
test_sizeThe proportion of data to be used for testing (between 0 and 1).
seedThe random seed for shuffling the data.
Examples
linreg.cpp.

Definition at line 279 of file linreg.cpp.

281  {
282  if (x.empty() || y.empty()) {
283  _log_.log(ERROR, "Training data is empty.");
284  return;
285  }
286 
287  if (test_size <= 0 || test_size >= 1) {
288  _log_.log(ERROR, "Invalid `test_size`. Must be between 0 - 1.");
289  return;
290  }
291 
292  size_t data_size = x.size();
293  size_t test_data_size = static_cast<size_t>(test_size * data_size);
294 
295  // Shuffle the data randomly if specified
296  if (shuffle == true) {
297  // Create vector of indices
298  std::vector<size_t> indices(data_size);
299  // Fill vector sequentially w/ `iota`
300  std::iota(indices.begin(), indices.end(), 0);
301  // Randomly shuffle vector indices from start to end
302  std::shuffle(indices.begin(),
303  indices.end(),
304  std::default_random_engine(seed));
305 
306  // Clear training and testing data vectors
307  x_train.clear();
308  y_train.clear();
309  x_test.clear();
310  y_test.clear();
311 
312  // Split the data into training and testing sets based on shuffled
313  // indices
314  for (size_t i = 0; i < data_size; ++i) {
315  if (i < test_data_size) {
316  // Append x test vector with shuffled x value
317  x_test.push_back(x[indices[i]]);
318  y_test.push_back(y[indices[i]]);
319  } else {
320  // Append x training vector with suffled x value
321  x_train.push_back(x[indices[i]]);
322  y_train.push_back(y[indices[i]]);
323  }
324  }
325  } else {
326  // Without shuffling, split the data without changing its order by
327  // assigning the first training element to the training set
328  x_train.assign(x.begin(), x.begin() + data_size - test_data_size);
329  y_train.assign(y.begin(), y.begin() + data_size - test_data_size);
330  // Assign the 1+ testing elements to the testing test
331  x_test.assign(x.begin() + data_size - test_data_size, x.end());
332  y_test.assign(y.begin() + data_size - test_data_size, y.end());
333  }
334 }
int64_t data_size()
Get the number of entries (xi, yi) in the data set.
Definition: linreg.cpp:89
std::vector< long double > x_test
Definition: linreg.hpp:78
std::vector< long double > y_test
Definition: linreg.hpp:80

References _log_, ERROR, and gpmp::core::Logger::log().

Referenced by test_train().

Member Data Documentation

◆ coeff

long double gpmp::ml::LinearRegression::coeff

Store the coefficient/slope in the best fitting line

Definition at line 60 of file linreg.hpp.

Referenced by LinearRegression().

◆ constant

long double gpmp::ml::LinearRegression::constant

Store the constant term in the best fitting line

Definition at line 62 of file linreg.hpp.

Referenced by LinearRegression().

◆ sum_x

long double gpmp::ml::LinearRegression::sum_x

Contains sum of all (i-th x)

Definition at line 66 of file linreg.hpp.

Referenced by LinearRegression().

◆ sum_x_square

long double gpmp::ml::LinearRegression::sum_x_square

Contains sum of square of all (i-th x)

Definition at line 70 of file linreg.hpp.

Referenced by LinearRegression().

◆ sum_xy

long double gpmp::ml::LinearRegression::sum_xy

Contains sum of product of all (i-th x) and (i-th y)

Definition at line 64 of file linreg.hpp.

Referenced by LinearRegression().

◆ sum_y

long double gpmp::ml::LinearRegression::sum_y

Contains sum of all (i-th y)

Definition at line 68 of file linreg.hpp.

Referenced by LinearRegression().

◆ sum_y_square

long double gpmp::ml::LinearRegression::sum_y_square

Contains sum of square of all (i-th y)

Definition at line 72 of file linreg.hpp.

Referenced by LinearRegression().

◆ x

std::vector<long double> gpmp::ml::LinearRegression::x

Dynamic array which is going to contain all (i-th x)

Examples
linreg.cpp.

Definition at line 56 of file linreg.hpp.

Referenced by test_train().

◆ x_test

std::vector<long double> gpmp::ml::LinearRegression::x_test

Vector holding x testing data

Examples
linreg.cpp.

Definition at line 78 of file linreg.hpp.

Referenced by test_train().

◆ x_train

std::vector<long double> gpmp::ml::LinearRegression::x_train

Vector holding x training data

Definition at line 74 of file linreg.hpp.

◆ y

std::vector<long double> gpmp::ml::LinearRegression::y

Dynamic array which is going to contain all (i-th y)

Examples
linreg.cpp.

Definition at line 58 of file linreg.hpp.

Referenced by test_train().

◆ y_test

std::vector<long double> gpmp::ml::LinearRegression::y_test

Vector holding y testing data

Examples
linreg.cpp.

Definition at line 80 of file linreg.hpp.

Referenced by test_train().

◆ y_train

std::vector<long double> gpmp::ml::LinearRegression::y_train

Vector holding y training data

Definition at line 76 of file linreg.hpp.


The documentation for this class was generated from the following files: