Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,41 @@ public void New_SimpleTrainAndPredict()
Assert.True(input.Sentiment && prediction.Score > 1 || !input.Sentiment && prediction.Score < -1);
}
}

/// <summary>
/// Start with a dataset in a text file. Run text featurization on text values.
/// Train a linear model over that. (I am thinking sentiment classification.)
/// Out of the result, produce some structure over which you can get predictions programmatically
/// (for example, the prediction does not happen over a file as it did during training).
/// Uses Symbolic SDCA Trainer.
/// </summary>
[Fact]
public void SimpleTrainAndPredictSymSGD()
{
var ml = new MLContext(seed: 1, conc: 1);
var data = ml.Data.ReadFromTextFile<SentimentData>(GetDataPath(TestDatasets.Sentiment.trainFilename), hasHeader: true);

// Pipeline.
var pipeline = ml.Transforms.Text.FeaturizeText("SentimentText", "Features")
.AppendCacheCheckpoint(ml)
.Append(ml.BinaryClassification.Trainers.SymbolicStochasticGradientDescent("Label", "Features", advancedSettings: s => s.NumberOfThreads = 1));

// Train.
var model = pipeline.Fit(data);

// Create prediction engine and test predictions.
var engine = model.CreatePredictionEngine<SentimentData, SentimentPrediction>(ml);

// Take a couple examples out of the test data and run predictions on top.
var testData = ml.Data.ReadFromTextFile<SentimentData>(GetDataPath(TestDatasets.Sentiment.testFilename), hasHeader: true)
.AsEnumerable<SentimentData>(ml, false);
foreach (var input in testData.Take(5))
{
var prediction = engine.Predict(input);
// Verify that predictions match and scores are separated from zero.
Assert.Equal(input.Sentiment, prediction.Sentiment);
Assert.True(input.Sentiment && prediction.Score > 1 || !input.Sentiment && prediction.Score < -1);
}
}
}
}
43 changes: 0 additions & 43 deletions test/Microsoft.ML.Tests/Scenarios/PipelineApi/Evaluation.cs

This file was deleted.

44 changes: 0 additions & 44 deletions test/Microsoft.ML.Tests/Scenarios/PipelineApi/Metacomponents.cs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading