我试图在这里实现线性回归的代码,但由于返回几个错误而无法编译std::sort。
#include "LinearRegression.h"
#include <iostream>
#include <algorithm>
#include <vector>
bool LinearRegression::custom_sort(double a, double b) /*sorts based on absolute min value or error*/
{
double a1 = abs(a-0);
double b1 = abs(b-0);
return a1<b1;
}
void LinearRegression::predict()
{
/*Intialization Phase*/
double x[] = { 1, 2, 4, 3, 5 }; //defining x values
double y[] = { 1, 3, 3, 2, 5 }; //defining y values
double err;
double b0 = 0; //initializing b0
double b1 = 0; //initializing …Run Code Online (Sandbox Code Playgroud)