public void TestTrain()
        {

            double[][] x = {
                new [] {1.0},
                new [] {3.0},
                new [] {2.0},
                new [] {200.0},
                new [] {230.0}};

            double[][] y = {
                new [] {1.0},
                new [] {1.0},
                new [] {1.0},
                new [] {0.0},
                new [] {0.0}
        };


            var trainingData = BasicData.ConvertArrays(x, y);
            var regression = new MultipleLinearRegression(1) {LinkFunction = new LogitLinkFunction()};
            var train = new TrainReweightLeastSquares(regression, trainingData);
            train.Iteration();

            double[] input = { 0 };
            double[] output = regression.ComputeRegression(input);
            Assert.AreEqual(0.883301730269988, output[0], AIFH.DefaultPrecision);
        }
Esempio n. 2
0
        /// <summary>
        /// Run the example.
        /// </summary>
        public void Process()
        {
            // read the iris data from the resources
            Assembly assembly = Assembly.GetExecutingAssembly();
            var res = assembly.GetManifestResourceStream("AIFH_Vol1.Resources.breast-cancer-wisconsin.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();

            ds.DeleteUnknowns();
            ds.DeleteColumn(0);
            ds.ReplaceColumn(9, 4, 1, 0);
            var trainingData = ds.ExtractSupervised(0, 9, 9, 1);

            var reg = new MultipleLinearRegression(9) {LinkFunction = new LogitLinkFunction()};
            var train = new TrainReweightLeastSquares(reg, trainingData);

            int iteration = 0;
            do
            {
                iteration++;
                train.Iteration();
                Console.WriteLine("Iteration #" + iteration + ", Error: " + train.Error);
            } while (iteration < 1000 && train.Error > 0.01);

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


        }