public void JudgeRegression(Point[] parray, int n, double x, string real) { if (parray.Length < n) { Response.Write("点的数量小于 n,无法进行线性回归"); return; } double[] xishu = ClassLeastSquares.MultiLine(parray, n); double y = 0; for (int i = 0; i < xishu.Length; i++) { y += xishu[i] * Math.Pow(x, i); } Response.Write("输入身高为" + x.ToString() + string.Format(",{0}次函数预测体重为", n) + y.ToString() + ",真实体重" + real + "</br>"); }
public void MultiRegression(Point[] array) { if (array.Length < 2) { Response.Write("点的数量小于2,无法进行回归!"); return; } double[] xishu = ClassLeastSquares.MultiLine(array, 2); string expr = ""; for (int i = 0; i < xishu.Length; i++) { expr += xishu[i].ToString() + "*x^" + i + "+"; expr = expr.Substring(0, expr.Length - 1); } Response.Write("回归二次方程为:y=" + expr); }
public void MultiLinearRegression(Point[] points, int times) { if (points.Length < 2) { Response.Write("点的数量小于2,无法进行线性回归"); return; } double[] coefficients = ClassLeastSquares.MultiLine(points, times); string expr = ""; for (int i = 0; i < coefficients.Length; i++) { expr += coefficients[i].ToString() + "*x^" + i + "+"; } expr = expr.Substring(0, expr.Length - 1); Response.Write(string.Format("线性回归{0}次方程:y=", times) + expr); }
/// <summary> ///通过最小二乘法进行二次方程的拟合 /// </summary> /// <param name="parray"></param> public void MultiLineRegression(Point[] parray) { //点数不能小于2 if (parray.Length < 2) { Response.Write("点的数量小于2,无法进行线性回归"); return; } //MultiLine的第一个参数,是已经存在的点的集合,第二个参数是拟合的方程的最高次幂 //返回的是double[]类型的数组,这个数组放的就是方程的系数 double[] xishu = ClassLeastSquares.MultiLine(parray, 2); string expr = ""; for (int i = 0; i < xishu.Length; i++) { expr += xishu[i].ToString() + "*x^" + i + "+"; } Response.Write("线性回归方程为: y = " + expr); }
public void RegressionN(Point[] parray, int n) { //点数不能小于 n if (parray.Length < n) { Response.Write("点的数量小于 n,无法进行线性回归"); return; } //MultiLine 的第一个参数,是已经存在的点的集合,第二个参数是拟合的方程的最高 次幂 //返回的是 double[]类型的数组,这个数组放的就是方程的系数 double[] xishu = ClassLeastSquares.MultiLine(parray, n); string expr = ""; for (int i = 0; i < xishu.Length; i++) { expr += xishu[i].ToString() + "*x^" + i + "+"; } expr = expr.Substring(0, expr.Length - 1); Response.Write(string.Format("{0}次", n) + "线性回归方程为: y = " + expr); }