public void Process()
        {
            // read the iris data from the resources
            Assembly assembly = Assembly.GetExecutingAssembly();
            var res = assembly.GetManifestResourceStream("AIFH_Vol1.Resources.abalone.csv");

            // did we fail to read the resouce
            if (res == null)
            {
                Console.WriteLine("Can't read iris data from embedded resources.");
                return;
            }

            // load the data
            var istream = new StreamReader(res);
            DataSet ds = DataSet.Load(istream);
            istream.Close();

            // The following ranges are setup for the Abalone data set.  If you wish to normalize other files you will
            // need to modify the below function calls other files.
            ds.EncodeOneOfN(0, 0, 1);
            istream.Close();

            var trainingData = ds.ExtractSupervised(0, 10, 10, 1);

            var reg = new MultipleLinearRegression(10);
            var train = new TrainLeastSquares(reg, trainingData);
            train.Iteration();

            Query(reg, trainingData);
            Console.WriteLine("Error: " + train.Error);

        }
Пример #2
0
        public void TestTrain()
        {
            double[][] x = {
                new [] {5.0, 10.0, 2.0},
                new []{10.0, 20.0, 4.0},
                new []{15.0, 30.0, 6.0},
                new []{20.0, 40.0, 8.0},
                new []{25.0, 50.0, 10.0}};

            double[][] y = {
                new []{70.0},
                new []{132.0},
                new []{194.0},
                new []{256.0},
                new []{318.0}
            };

            var trainingData = BasicData.ConvertArrays(x, y);
            var regression = new MultipleLinearRegression(3);
            var train = new TrainLeastSquares(regression, trainingData);
            train.Iteration();

            Assert.AreEqual(8, regression.LongTermMemory[0], 0.0001);
            Assert.AreEqual(-54.8, regression.LongTermMemory[1], 0.0001);
            Assert.AreEqual(8, regression.LongTermMemory[2], 0.0001);
            Assert.AreEqual(1, train.R2, 0.0001);
            Assert.AreEqual(0, train.Error, AIFH.DefaultPrecision);

            for (int i = 0; i < x.Length; i++)
            {
                double[] output = regression.ComputeRegression(x[i]);
                Assert.AreEqual(y[i][0], output[0], 0.0001);
            }
        }