-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Extended SentimentPrediction for easier display #832
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,20 +119,21 @@ public static void Evaluate(MLContext mlContext, ITransformer model, IDataView s | |
| // The Accuracy metric gets the accuracy of a model, which is the proportion | ||
| // of correct predictions in the test set. | ||
|
|
||
| // The AreaUnderRocCurve metric is an indicator of how confident the model is | ||
| // correctly classifying the positive and negative classes as such. | ||
| // The AreaUnderROCCurve metric is equal to the probability that the algorithm ranks | ||
| // a randomly chosen positive instance higher than a randomly chosen negative one | ||
| // (assuming 'positive' ranks higher than 'negative'). | ||
|
|
||
| // The F1Score metric gets the model's F1 score. | ||
| // F1 is a measure of tradeoff between precision and recall. | ||
| // The F1 score is the harmonic mean of precision and recall: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess if we say mean, it is implied that it mixes both precision and recall into one metric. |
||
| // 2 * precision * recall / (precision + recall). | ||
|
|
||
| // <SnippetDisplayMetrics> | ||
| Console.WriteLine(); | ||
| Console.WriteLine("Model quality metrics evaluation"); | ||
| Console.WriteLine("--------------------------------"); | ||
| Console.WriteLine($" Accuracy: {metrics.Accuracy:P2}"); | ||
| Console.WriteLine($"Area Under Roc Curve: {metrics.AreaUnderRocCurve:P2}"); | ||
| Console.WriteLine($" F1Score: {metrics.F1Score:P2}"); | ||
| Console.WriteLine($"Accuracy: {metrics.Accuracy:P2}"); | ||
| Console.WriteLine($"Auc: {metrics.AreaUnderRocCurve:P2}"); | ||
| Console.WriteLine($"F1Score: {metrics.F1Score:P2}"); | ||
| Console.WriteLine("=============== End of model evaluation ==============="); | ||
| //</SnippetDisplayMetrics> | ||
|
|
||
|
|
@@ -159,7 +160,7 @@ private static void UseModelWithSingleItem(MLContext mlContext, ITransformer mod | |
| Console.WriteLine("=============== Prediction Test of model with a single sample and test dataset ==============="); | ||
|
|
||
| Console.WriteLine(); | ||
| Console.WriteLine($"Sentiment: {sampleStatement.SentimentText} | Prediction: {(Convert.ToBoolean(resultprediction.Prediction) ? "Positive" : "Negative")} | Probability: {resultprediction.Probability} "); | ||
| Console.WriteLine($"Sentiment: {resultprediction.SentimentText} | Prediction: {(Convert.ToBoolean(resultprediction.Prediction) ? "Positive" : "Negative")} | Probability: {resultprediction.Probability} "); | ||
|
|
||
| Console.WriteLine("=============== End of Predictions ==============="); | ||
| Console.WriteLine(); | ||
|
|
@@ -200,20 +201,15 @@ public static void UseModelWithBatchItems(MLContext mlContext, ITransformer mode | |
| // </SnippetAddInfoMessage> | ||
|
|
||
| Console.WriteLine(); | ||
|
|
||
| // Builds pairs of (sentiment, prediction) | ||
| // <SnippetBuildSentimentPredictionPairs> | ||
| IEnumerable<(SentimentData sentiment, SentimentPrediction prediction)> sentimentsAndPredictions = sentiments.Zip(predictedResults, (sentiment, prediction) => (sentiment, prediction)); | ||
| // </SnippetBuildSentimentPredictionPairs> | ||
|
|
||
|
|
||
| // <SnippetDisplayResults> | ||
| foreach ((SentimentData sentiment, SentimentPrediction prediction) item in sentimentsAndPredictions) | ||
| foreach (SentimentPrediction prediction in predictedResults) | ||
| { | ||
| Console.WriteLine($"Sentiment: {item.sentiment.SentimentText} | Prediction: {(Convert.ToBoolean(item.prediction.Prediction) ? "Positive" : "Negative")} | Probability: {item.prediction.Probability} "); | ||
| Console.WriteLine($"Sentiment: {prediction.SentimentText} | Prediction: {(Convert.ToBoolean(prediction.Prediction) ? "Positive" : "Negative")} | Probability: {prediction.Probability} "); | ||
|
|
||
| } | ||
| Console.WriteLine("=============== End of predictions ==============="); | ||
| // </SnippetDisplayResults> | ||
| // </SnippetDisplayResults> | ||
| } | ||
|
|
||
| } | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we removing this?