2016-11-20 74 views
0

我有下面的代码,我设法拼凑:如何计算的均方误差

private void CalcMSE(List<Point> data) 
{ 
    double sum = 0.0; 

     foreach (Point item in data) 
     { 
      double difference = item.m_x - item.m_y; 
      sum = sum + difference * difference; 
     } 
    double mse = sum/x; //<-- Don't know what x should be! 
    Console.WriteLine("The mean square error is {0}",mse) ; 
} 

输入是:

point.m_x = 3; 
point.m_y = 1; 
pointList.Add(point); 

point.m_x = 4; 
point.m_y = 4; 
pointList.Add(point); 

point.m_x = 5; 
point.m_y = 6; 
pointList.Add(point); 

point.m_x = 6; 
point.m_y = 6; 
pointList.Add(point); 

point.m_x = 8; 
point.m_y = 10; 
pointList.Add(point); 

根据那些在知道MSE应是0.77和MSR 40.89

但我不知道x的“公式”是什么(请参阅代码注释)。

任何人都可以帮助我了解线性回归?

这里的。OUPUTS应该是什么

desired ouput

+0

什么'd.Count()'? – Kinetic

+1

data.Count()或Lenght ...或者让一个计数变量在for循环中增加一个。 x将等于计数。 –

+0

你确定...?它给出的值为8 d.Count() – Eminem

回答

0

首先,我想你应该总是添加到列表point = new Point(x,y)之前创建一个新的起点,我不认为list.add创建一个副本。

作为X,我想data.Count()会做