Skip to content

Commit

Permalink
Add pattern match
Browse files Browse the repository at this point in the history
  • Loading branch information
jwood803 committed Aug 22, 2020
1 parent 24c729d commit a311ea2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
23 changes: 19 additions & 4 deletions MLNetExamples/SentimentAnalysis/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,28 @@ static void Main(string[] args)

var prediction = predictionEngine.Predict(new SentimentData { Text = "I would buy MSFT shares." });

Console.WriteLine($"Prediction - {prediction.Prediction} with score - {prediction.Score}");
Console.WriteLine($"Prediction - {prediction.Prediction} with probability - {prediction.Probability}");

var newPrediction = predictionEngine.Predict(new SentimentData { Text = "TWTR may close at a low today." });

Console.WriteLine($"Prediction - {newPrediction.Prediction} with score - {newPrediction.Score}");

Console.ReadLine();
Console.WriteLine($"Prediction - {newPrediction.Prediction} with probability - {newPrediction.Probability}");

var anotherPrediction = predictionEngine.Predict(new SentimentData { Text = "TSLA is at an all time high." });

switch (anotherPrediction.Probability)
{
case float p when p < .5:
Console.WriteLine($"TSLA sentiment is negative with probability {p}");
break;
case float p when p >= .5 && p <= .7:
Console.WriteLine($"TSLA sentiment is neutral with probability {p}");
break;
case float p when p > .7:
Console.WriteLine($"TSLA sentiment is positive with probability {p}");
break;
default:
break;
}
}
}
}
4 changes: 2 additions & 2 deletions MLNetExamples/SentimentAnalysis/SentimentAnalysis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ML" Version="1.5.2-29213-2" />
<PackageReference Include="Microsoft.ML" Version="1.5.2-29219-1" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit a311ea2

Please sign in to comment.