Пример #1
0
        static void TrainEvaluatePredict(TrainerBase trainer, BostonHousingData newSample)
        {
            Console.WriteLine("*******************************");
            Console.WriteLine($"{ trainer.Name }");
            Console.WriteLine("*******************************");

            trainer.Fit("..\\Data\\boston_housing.csv");

            var modelMetrics = trainer.Evaluate();

            Console.WriteLine($"Loss Function: {modelMetrics.LossFunction:0.##}{Environment.NewLine}" +
                              $"Mean Absolute Error: {modelMetrics.MeanAbsoluteError:#.##}{Environment.NewLine}" +
                              $"Mean Squared Error: {modelMetrics.MeanSquaredError:#.##}{Environment.NewLine}" +
                              $"RSquared: {modelMetrics.RSquared:0.##}{Environment.NewLine}" +
                              $"Root Mean Squared Error: {modelMetrics.RootMeanSquaredError:#.##}");

            trainer.Save();

            var predictor  = new Predictor();
            var prediction = predictor.Predict(newSample);

            Console.WriteLine("------------------------------");
            Console.WriteLine($"Prediction: {prediction.MedianPrice:#.##}");
            Console.WriteLine("------------------------------");
        }
Пример #2
0
        static void Main(string[] args)
        {
            var newSample = new BostonHousingData
            {
                Age                       = 65.2f,
                CrimeRate                 = 0.00632f,
                EmployCenterDistance      = 4.0900f,
                HighwayAccecabilityRadius = 15.3f,
                NOConcetration            = 0.538f,
                NumOfRoomsPerDwelling     = 6.575f,
                Proportion                = 1f,
                PTRatio                   = 15.3f,
                RiverCoast                = 0f,
                TaxRate                   = 296f,
                Zoned                     = 23f
            };

            var ogd = new OGDBostonTrainer();

            TrainEvaluatePredict(ogd, newSample);

            var sdca = new SdcaRegressionBostonTrainer();

            TrainEvaluatePredict(sdca, newSample);
        }
Пример #3
0
        /// <summary>
        /// Runs prediction on new data.
        /// </summary>
        /// <param name="newSample">New data sample.</param>
        /// <returns>Predictions made by model.</returns>
        public BostonHousingPricePredictions Predict(BostonHousingData newSample)
        {
            LoadModel();

            var predictionEngine = _mlContext.Model
                                   .CreatePredictionEngine <BostonHousingData, BostonHousingPricePredictions>(_model);

            return(predictionEngine.Predict(newSample));
        }
Пример #4
0
        /// <summary>
        /// データのクリーニングを実施します。
        /// </summary>
        public void Clean()
        {
            using (var writer = new StreamWriter(CleanedFilePath))
            {
                writer.Write(string.Join(",", BostonHousingData.EnumerableColumnNames().ToArray()));
                foreach (var data in EnumerableRawLine(RawFilePath))
                {
                    writer.WriteLine();
                    writer.Write(ConvertToCommaLine(data));
                }

                writer.Flush();
            }
        }