# 关于多元线性回归C#编程

0

``` private void btCount_Click(object sender, EventArgs e)
{
if(txtData.Text.Trim()=="")
{
showMsg("数据不能为空！"); return;
}
try
{
List<List<double>> X;
List<double> Y;
getData(out X, out Y);
int i, j, m = X[0].Count, n = X.Count;
txtResult.Text = "";
RegresionClass reg = new RegresionClass(X, Y);
double[] P = reg.getParamters();
String s = "";
if (P != null)
{
for (j = 0; j < m; j++) s = s + "P[" + j.ToString() + "]=" + P[j].ToString() + "\r\n";
showResult(s);
s = "   实际值,   预测值\r\n";
double TSS = 0, RSS = 0, aveY = 0;
for (i = 0; i < n; i++)
{
double y = 0;
for (j = 0; j < m; j++) y = y + P[j] * X[i][j];
s = s + format(Y[i], 2, 8) + ",  " + format(y, 2, 8) + "\r\n";
aveY += Y[i];
TSS += Y[i] * Y[i];// 总平方和
RSS += (y - Y[i]) * (y - Y[i]);//回归平方和
}
showResult(s);
aveY = aveY / n;
TSS = TSS - n * aveY * aveY;
showResult("TSS=" + TSS.ToString());
showResult("RR=" + (1 - RSS / TSS).ToString());
}

}
catch (Exception exp) { showMsg(exp.Message); }
}```

WulTea | 初学一级 | 园豆：114

0

0

http://blog.csdn.net/flowingflying/article/details/8070181

您需要登录以后才能回答，未注册用户请先注册