C#线性回归给出2组数据 [英] c# linear regression given 2 sets of data

查看:236
本文介绍了C#线性回归给出2组数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2组数据-一组是平均排名,另一组是得分,因此对于每个职位,我都有一项的预测得分-

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,...};

我需要创建一个预测平均排名得分的函数,因此给定位置为1.7的新项目. 我理解该函数应该是y = a * x + b之类的东西,但是我该怎么做呢?

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?

任何帮助将不胜感激!

推荐答案

是的,您必须构建一个线性函数

Yes, you have to build a linear function

  y = a * x + b

为此,您必须计算总和(x预测变量的值,而y-是相应的结果):

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

所以

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

这篇关于C#线性回归给出2组数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆