public class MultiRegressionDemo { public static void Execute() { // 2 dimensions MultipleLinearRegression target = new MultipleLinearRegression(2, true); double[][] inputs = { new double[] { 1, 8 }, new double[] { 2, 29 }, new double[] { 3, 2 }, new double[] { 0, 1 }, new double[] { 5, 6 }, new double[] { 4, 7 }, new double[] { 14, 17 }, }; double[] outputs = { 9, 4, 3, 2, 5, 12, 7 }; double error = target.Regress(inputs, outputs); Console.WriteLine("the regression error is '{0}'", error); // As result, we will be given the following: double a = target.Coefficients[0]; // a = 0 double b = target.Coefficients[1]; // b = 0 double c = target.Coefficients[2]; // c = 1 Console.WriteLine("line functions is :{0}x + {1}y + {2}", a, b, c); } } class Program { static void Main(string[] args) { MultiRegressionDemo.Execute(); Console.ReadLine(); } }
运行结果: