13 #include <openGPMP/gpmp.h>
24 dt.
csv_read(
"../../data/school_scores.csv", {
"Year",
"GPA"});
29 std::vector<std::string> columns = {
"Year",
"GPA"};
40 double v1_v = reg.
predict(v1, reg.
x);
43 "Predicted value at " + std::to_string(v1) +
" = " +
44 std::to_string(v1_v));
47 "Error value at " + std::to_string(v1) +
" = " +
48 std::to_string(v1_e));
60 printf(
"Predicted value at %d = %f\n", v1, v1_v_after_split);
61 printf(
"Error value at %d = %f\n\n", v1, v1_e_after_split);
63 "Predicted value at " + std::to_string(v1) +
" = " +
64 std::to_string(v1_v_after_split));
67 "Error value at " + std::to_string(v1) +
" = " +
68 std::to_string(v1_e_after_split));
74 _log_.
log(
INFO,
"MSE = " + std::to_string(mse_after_split));
75 _log_.
log(
INFO,
"R2 score = " + std::to_string(r_squared_after_split));
DataTableStr csv_read(std::string filename, std::vector< std::string > columns={})
Reads a CSV file and returns a DataTableStr parses CSV files and stores all data as strings.
void log(LogLevel level, const std::string &message)
Logs a message with the specified log level.
void best_fit()
Calculates and displays the best fitting line based on training data.
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.
long double error_in(long double num)
Calculates the error (residual) for a given independent variable value.
long double predict(long double _x) const
Predict a value based on the input.
std::vector< long double > y
void split_data(double test_size, unsigned int seed, bool shuffle)
Splits the data into training and testing sets.
std::vector< long double > x_test
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).
std::vector< long double > y_test
std::vector< long double > x
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.
std::pair< std::vector< std::string >, std::vector< std::vector< std::string > > > DataTableStr
static gpmp::core::Logger _log_