public void TrainOneVersusAll() { string dataPath = GetDataPath("iris.txt"); var pipeline = new Legacy.LearningPipeline(seed: 1, conc: 1); pipeline.Add(new TextLoader(dataPath).CreateFrom <IrisData>(useHeader: false)); pipeline.Add(new ColumnConcatenator(outputColumn: "Features", "SepalLength", "SepalWidth", "PetalLength", "PetalWidth")); pipeline.Add(OneVersusAll.With(new StochasticDualCoordinateAscentBinaryClassifier())); var model = pipeline.Train <IrisData, IrisPrediction>(); var testData = new TextLoader(dataPath).CreateFrom <IrisData>(useHeader: false); var evaluator = new ClassificationEvaluator(); ClassificationMetrics metrics = evaluator.Evaluate(model, testData); CheckMetrics(metrics); var trainTest = new TrainTestEvaluator() { Kind = MacroUtilsTrainerKinds.SignatureMultiClassClassifierTrainer }.TrainTestEvaluate <IrisData, IrisPrediction>(pipeline, testData); CheckMetrics(trainTest.ClassificationMetrics); }
void Metacomponents() { var dataPath = GetDataPath(IrisDataPath); var pipeline = new LearningPipeline(seed: 1, conc: 1); pipeline.Add(new TextLoader(dataPath).CreateFrom <IrisData>(useHeader: false)); pipeline.Add(new Dictionarizer(new[] { "Label" })); pipeline.Add(new ColumnConcatenator(outputColumn: "Features", "SepalLength", "SepalWidth", "PetalLength", "PetalWidth")); // This will throw exception during training time if you specify any other than binary classifier. pipeline.Add(OneVersusAll.With(new StochasticDualCoordinateAscentBinaryClassifier())); var model = pipeline.Train <IrisData, IrisPrediction>(); var testData = new TextLoader(dataPath).CreateFrom <IrisData>(useHeader: false); var evaluator = new ClassificationEvaluator(); ClassificationMetrics metrics = evaluator.Evaluate(model, testData); var prediction = model.Predict(new IrisData { PetalLength = 1, PetalWidth = 2, SepalLength = 1.4f, SepalWidth = 1.6f }); }