Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating OVA tests #2956

Merged
merged 1 commit into from
Mar 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 2 additions & 60 deletions test/Microsoft.ML.Functional.Tests/Training.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,23 +451,12 @@ public void MetacomponentsFunctionAsExpectedOva()
separatorChar: TestDatasets.iris.fileSeparator);

// Create a model training an OVA trainer with a binary classifier.
var anomalyDetectionTrainer = mlContext.AnomalyDetection.Trainers.RandomizedPca();
var anomalyDetectionPipeline = mlContext.Transforms.Concatenate("Features", Iris.Features)
.AppendCacheCheckpoint(mlContext)
.Append(mlContext.Transforms.Conversion.MapValueToKey("Label"))
.Append(mlContext.MulticlassClassification.Trainers.OneVersusAll(anomalyDetectionTrainer))
.Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel"));

// Fit the binary classification pipeline.
Assert.Throws<InvalidOperationException>(() => anomalyDetectionPipeline.Fit(data));

// Create a model training an OVA trainer with a binary classifier.
var binaryclassificationTrainer = mlContext.BinaryClassification.Trainers.LogisticRegression(
var binaryClassificationTrainer = mlContext.BinaryClassification.Trainers.LogisticRegression(
new LogisticRegressionBinaryClassificationTrainer.Options { MaximumNumberOfIterations = 10, NumberOfThreads = 1, });
var binaryClassificationPipeline = mlContext.Transforms.Concatenate("Features", Iris.Features)
.AppendCacheCheckpoint(mlContext)
.Append(mlContext.Transforms.Conversion.MapValueToKey("Label"))
.Append(mlContext.MulticlassClassification.Trainers.OneVersusAll(binaryclassificationTrainer));
.Append(mlContext.MulticlassClassification.Trainers.OneVersusAll(binaryClassificationTrainer));

// Fit the binary classification pipeline.
var binaryClassificationModel = binaryClassificationPipeline.Fit(data);
Expand All @@ -477,53 +466,6 @@ public void MetacomponentsFunctionAsExpectedOva()

// Evaluate the model.
var binaryClassificationMetrics = mlContext.MulticlassClassification.Evaluate(binaryClassificationPredictions);

// Create a model training an OVA trainer with a clustering trainer.
var kmeansTrainer = mlContext.Clustering.Trainers.KMeans(
new KMeansTrainer.Options { MaximumNumberOfIterations = 10, NumberOfThreads = 1, });

Assert.Throws<ArgumentOutOfRangeException>(() =>
mlContext.Transforms.Concatenate("Features", Iris.Features)
.AppendCacheCheckpoint(mlContext)
.Append(mlContext.Transforms.Conversion.MapValueToKey("Label"))
.Append(mlContext.MulticlassClassification.Trainers.OneVersusAll(kmeansTrainer))
.Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel")));

// Create a model training an OVA trainer with a multiclass classification trainer.
var multiclassTrainer = mlContext.MulticlassClassification.Trainers.LogisticRegression(
new LogisticRegressionMulticlassClassificationTrainer.Options { MaximumNumberOfIterations = 10, NumberOfThreads = 1, });
Assert.Throws<ArgumentOutOfRangeException>(() =>
mlContext.Transforms.Concatenate("Features", Iris.Features)
.AppendCacheCheckpoint(mlContext)
.Append(mlContext.Transforms.Conversion.MapValueToKey("Label"))
.Append(mlContext.MulticlassClassification.Trainers.OneVersusAll(multiclassTrainer))
.Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel")));

// Create a model training an OVA trainer with a ranking trainer.
var rankingTrainer = mlContext.Ranking.Trainers.FastTree(
new FastTreeRankingTrainer.Options { NumberOfTrees = 2, NumberOfThreads = 1, });
// Todo #2920: Make this fail somehow.
var rankingPipeline = mlContext.Transforms.Concatenate("Features", Iris.Features)
.AppendCacheCheckpoint(mlContext)
.Append(mlContext.Transforms.Conversion.MapValueToKey("Label"))
.Append(mlContext.MulticlassClassification.Trainers.OneVersusAll(rankingTrainer))
.Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel"));

// Fit the invalid pipeline.
Assert.Throws<ArgumentOutOfRangeException>(() => rankingPipeline.Fit(data));

// Create a model training an OVA trainer with a regressor.
var regressionTrainer = mlContext.Regression.Trainers.PoissonRegression(
new PoissonRegressionTrainer.Options { MaximumNumberOfIterations = 10, NumberOfThreads = 1, });
// Todo #2920: Make this fail somehow.
var regressionPipeline = mlContext.Transforms.Concatenate("Features", Iris.Features)
.AppendCacheCheckpoint(mlContext)
.Append(mlContext.Transforms.Conversion.MapValueToKey("Label"))
.Append(mlContext.MulticlassClassification.Trainers.OneVersusAll(regressionTrainer))
.Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel"));

// Fit the invalid pipeline.
Assert.Throws<ArgumentOutOfRangeException>(() => regressionPipeline.Fit(data));
}
}
}