static void Main(string[] args) { TextLoader loader = TextLoader.Create(typeof(IrisData)); loader.Separator = ","; IDataView trainingData = loader.Read("iris-data.txt"); var estimator = new ValueToKeyMappingEstimator("Label") .Append(new ColumnConcatenatingEstimator("Features", "SepalLength", "SepalWidth", "PetalLength", "PetalWidth")) .Append(new SdcaMultiClassTrainer()) .Append(new KeyToValueMappingEstimator("PredictedLabel")); var model = estimator.Train <IrisData, IrisPrediction>(trainingData); IrisData newInput = new IrisData() { SepalLength = 3.3f, SepalWidth = 1.6f, PetalLength = 0.2f, PetalWidth = 5.1f, }; IrisPrediction prediction = model.Predict(newInput); Console.WriteLine($"Predicted flower type is: {prediction.PredictedLabel}"); }
static void Main(string[] args) { TextLoader loader = TextLoader.Create(typeof(IrisData), separator: ","); IDataView trainingData = loader.Read("iris-data.txt"); var pipeline = new EstimatorChain(); pipeline.Add(new ValueToKeyMappingEstimator(nameof(IrisData.Label))); pipeline.Add(new ColumnConcatenatingEstimator( inputColumns: new[] { nameof(IrisData.SepalLength), nameof(IrisData.SepalWidth), nameof(IrisData.PetalLength), nameof(IrisData.PetalWidth) }, outputColumn: DefaultColumnNames.Features)); pipeline.Add(new SdcaMultiClassTrainer( featureColumn: DefaultColumnNames.Features, labelColumn: nameof(IrisData.Label), predictedLabelColumn: nameof(IrisPrediction.PredictedLabel))); pipeline.Add(new KeyToValueMappingEstimator(nameof(IrisPrediction.PredictedLabel))); var model = pipeline.Fit(trainingData); IrisData newInput = new IrisData() { SepalLength = 3.3f, SepalWidth = 1.6f, PetalLength = 0.2f, PetalWidth = 5.1f, }; IrisPrediction prediction = model .MakePredictionFunction <IrisData, IrisPrediction>() .Predict(newInput); Console.WriteLine($"Predicted flower type is: {prediction.PredictedLabel}"); }