static void Main(string[] args) { var mlContext = new MLContext(); // Creates a loader which will help format the data var reader = mlContext.Data.CreateTextLoader( columns: new TextLoader.Column[] { new TextLoader.Column(CocoaPercent, DataKind.Single, 1), new TextLoader.Column("Label", DataKind.Single, 4) // Customer happiness is the label. The predicted features is called the Label. }, hasHeader: true // First line of the data file is a header and not data row ); IDataView trainingData = reader.Load(TrainDataPath); PreviewUtil.Show(trainingData); // Creates a pipeline - All operations like data operations, transformation, training are bundled as a pipeline var pipeline = mlContext.Transforms.Concatenate(outputColumnName: "Features", inputColumnNames: CocoaPercent) .Append(mlContext.Regression.Trainers.LbfgsPoissonRegression()); // Train the model var trainingModel = pipeline.Fit(trainingData); // Using the training for one-time prediction var predictionEngine = mlContext.Model.CreatePredictionEngine <ChocolateInput, ChocolateOutput>(trainingModel); // Get the prediction ChocolateOutput prediction = predictionEngine.Predict(new ChocolateInput() { CocoaPercent = 100 }); Console.WriteLine($"Predicted happiness: {prediction.CustomerHappiness}"); ChartGeneratorUtil.PlotRegressionChart(new PlotChartGeneratorModel() { Title = "Chocolate Consumer Happiness Prediction", LabelX = "Cocoa Percent", LabelY = "Customer Happiness", ImageName = "CocoaPercentToHappiness.png", PointsList = new List <PlotChartPointsList> { new PlotChartPointsList { Points = ChartGeneratorUtil.GetChartPointsFromFile(TrainDataPath, 1, 4).ToList() } }, MaxLimitY = ChartGeneratorUtil.GetMaxColumnValueFromFile(TrainDataPath, 4) + 10 }); Console.ReadKey(); }
static void Main(string[] args) { var mlContext = new MLContext(); TextLoader reader = mlContext.Data.CreateTextLoader( columns: new TextLoader.Column[] { new TextLoader.Column("Weight", DataKind.Single, 0), new TextLoader.Column("CocoaPercent", DataKind.Single, 1), new TextLoader.Column("Cost", DataKind.Single, 2), new TextLoader.Column("Label", DataKind.Single, 3) // Label is customer happiness. The predicted feature is called the label }, hasHeader: true); IDataView trainingData = reader.Load(TrainingDataPath); PreviewUtil.Show(trainingData); var pipeline = mlContext.Transforms.Concatenate("Features", "Weight") .Append(mlContext.Regression.Trainers.LbfgsPoissonRegression()); var trainingModel = pipeline.Fit(trainingData); /* Get the graph data */ /* Build the graph */ /* Calculate metrics */ /* Get the predictions */ /* Show Graph 3D */ // TODO: Add Graph, update instructions Console.ReadKey(); }