Exemplo n.º 1
0
        private static void TestLinearRegression()
        {
            var lrm = new LinearRegressionModel {
                Weights = np.array(new double[] { 2, 4, 6, 2, 2 })
            };
            var x = np.array(new double[][] { new double[] { 1, 1, 1, 1 } });

            var list = LinearRegressionModel.MatrixToDataSet(x);

            var resultat = lrm.Predict(list);

            Console.WriteLine(resultat.ToString());
        }
Exemplo n.º 2
0
        private static void TestFit()
        {
            var lrm = new LinearRegressionModel {
                Weights = np.array(new double[] { 2, 4, 6, 2, 2 })
            };
            var x = np.array(new double[, ] {
                { 1, 1, 1, 1 }, { 2, 5, 2, 2 }, { 2, 3, 2, 2 }, { 5, 2, 2, 2 }, { 2, 2, 3, 2 }, { 7, 2, 2, 2 }, { 2, 6, 2, 2 }, { 2, 4, 2, 2 }, { 2, 3, 3, 2 }, { 2, 2, 2, 8 }
            });

            var list = LinearRegressionModel.MatrixToDataSet(x);

            var yList = lrm.Predict(list);
            var y     = np.array(yList.Cast <double>().ToArray());

            Console.WriteLine($"Weights {lrm.Weights.ToString()}");
            Console.WriteLine($"X {x.ToString()}");
            Console.WriteLine($"Y { y.ToString()}");

            lrm.Fit(list, yList);

            Console.WriteLine($"Weights after fit {lrm.Weights.ToString()}");
        }