c# linear regression given 2 sets of data

☆樱花仙子☆ 提交于 2019-12-11 04:37:09

问题


I have 2 sets of data - one is an average position and the other a score so for every position, i have the predicted score of an item -

double[] positions = {0.1,0.2,0.3,0.45,0.46,...};
double[] scores = {1,1.2,1.5,2.2,3.4,...};

I need to create a function that predicts the score for average position, so given a new item with position 1.7. I under stand the function should be something like y=a*x + b but how do i get to it?

Any help will be appreciated!


回答1:


Yes, you have to build a linear function

  y = a * x + b

in order to do this you have to compute the sums (x is predictor's values and y - is corresponding results):

 sx  - sum of x's
 sxx - sum of x * x
 sy  - sum of y's
 sxy - sum of x * y

So

 a = (N * sxy - sx * sy) / (N * sxx - sx * sx);
 b = (sy - a * sx) / N;


来源:https://stackoverflow.com/questions/32433070/c-sharp-linear-regression-given-2-sets-of-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!