Last active
August 5, 2020 15:00
-
-
Save georgekosmidis/149f4f3cb6a0ade1961ddedd852b40d7 to your computer and use it in GitHub Desktop.
These gists are part of the blog post: https://blog.georgekosmidis.net/2020/07/22/a-hello-world-with-microsoft-machine-learning-framework-ml-net/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var trainer = mlContext.BinaryClassification.Trainers | |
.AveragedPerceptron(labelColumnName: "Sentiment", featureColumnName: "Features")); | |
var trainingPipeline = dataTransformPipeline.Append(trainer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Convert sentiment text into numeric features | |
var dataTransformPipeline = mlContext.Transforms.Text | |
.FeaturizeText("Features", "SentimentText"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var model = pipeline.Fit(trainingData); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var trainingData = mlContext.Data | |
.LoadFromTextFile<SentimentInput>(dataPath, separatorChar: ',', hasHeader: true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mlContext = new MLContext(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mlContext = new MLContext(); | |
DataViewSchema predictionPipelineSchema; | |
var model = mlContext.Model.Load("model.zip", out predictionPipelineSchema); | |
var predEngine = mlContext.Model.CreatePredictionEngine(model); | |
var sampleComment = new SentimentInput{ SentimentText = "This is very rude!" }; | |
var result = predEngine.Predict(sampleComment); | |
Console.WriteLine(result.Prediction); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make predictions on test data | |
IDataView predictions = model.Transform(testDataView); | |
// Evaluate model and return metrics | |
var metrics = mlContext.BinaryClassification | |
.Evaluate(predictions, labelColumnName: "Sentiment"); | |
// Print out accuracy metric | |
Console.WriteLine("Accuracy" + metrics.Accuracy); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment