Skip to content

Instantly share code, notes, and snippets.

@georgekosmidis
Last active August 5, 2020 15:00
Show Gist options
  • Save georgekosmidis/149f4f3cb6a0ade1961ddedd852b40d7 to your computer and use it in GitHub Desktop.
Save georgekosmidis/149f4f3cb6a0ade1961ddedd852b40d7 to your computer and use it in GitHub Desktop.
var trainer = mlContext.BinaryClassification.Trainers
.AveragedPerceptron(labelColumnName: "Sentiment", featureColumnName: "Features"));
var trainingPipeline = dataTransformPipeline.Append(trainer);
// Convert sentiment text into numeric features
var dataTransformPipeline = mlContext.Transforms.Text
.FeaturizeText("Features", "SentimentText");
var model = pipeline.Fit(trainingData);
var trainingData = mlContext.Data
.LoadFromTextFile<SentimentInput>(dataPath, separatorChar: ',', hasHeader: true);
var mlContext = new MLContext();
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);
// 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