Skip to content

Commit e6c8f39

Browse files
bamurtaughCESARDELATORRE
authored andcommitted
Removed regions to simplify code (dotnet#578)
1 parent 404cf49 commit e6c8f39

File tree

1 file changed

+0
-10
lines changed
  • samples/csharp/getting-started/BinaryClassification_SentimentAnalysis/SentimentAnalysis/SentimentAnalysisConsoleApp

1 file changed

+0
-10
lines changed

samples/csharp/getting-started/BinaryClassification_SentimentAnalysis/SentimentAnalysis/SentimentAnalysisConsoleApp/Program.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ internal static class Program
2121

2222
static void Main(string[] args)
2323
{
24-
#region try
2524
// Create MLContext to be shared across the model creation workflow objects
2625
// Set a random seed for repeatable/deterministic results across multiple trainings.
2726
var mlContext = new MLContext(seed: 1);
2827

29-
#region step1to3
3028
// STEP 1: Common data loading configuration
3129
IDataView dataView = mlContext.Data.LoadFromTextFile<SentimentIssue>(DataPath, hasHeader: true);
3230

@@ -40,18 +38,13 @@ static void Main(string[] args)
4038
// STEP 3: Set the training algorithm, then create and config the modelBuilder
4139
var trainer = mlContext.BinaryClassification.Trainers.SdcaLogisticRegression(labelColumnName: "Label", featureColumnName: "Features");
4240
var trainingPipeline = dataProcessPipeline.Append(trainer);
43-
#endregion
4441

45-
#region step4
4642
// STEP 4: Train the model fitting to the DataSet
4743
ITransformer trainedModel = trainingPipeline.Fit(trainingData);
48-
#endregion
4944

50-
#region step5
5145
// STEP 5: Evaluate the model and show accuracy stats
5246
var predictions = trainedModel.Transform(testData);
5347
var metrics = mlContext.BinaryClassification.Evaluate(data: predictions, labelColumnName: "Label", scoreColumnName: "Score");
54-
#endregion
5548

5649
ConsoleHelper.PrintBinaryClassificationMetrics(trainer.ToString(), metrics);
5750

@@ -63,19 +56,16 @@ static void Main(string[] args)
6356
// TRY IT: Make a single test prediction loding the model from .ZIP file
6457
SentimentIssue sampleStatement = new SentimentIssue { Text = "This is a very rude movie" };
6558

66-
#region consume
6759
// Create prediction engine related to the loaded trained model
6860
var predEngine = mlContext.Model.CreatePredictionEngine<SentimentIssue, SentimentPrediction>(trainedModel);
6961

7062
// Score
7163
var resultprediction = predEngine.Predict(sampleStatement);
72-
#endregion
7364

7465
Console.WriteLine($"=============== Single Prediction ===============");
7566
Console.WriteLine($"Text: {sampleStatement.Text} | Prediction: {(Convert.ToBoolean(resultprediction.Prediction) ? "Toxic" : "Non Toxic")} sentiment | Probability of being toxic: {resultprediction.Probability} ");
7667
Console.WriteLine($"================End of Process.Hit any key to exit==================================");
7768
Console.ReadLine();
78-
#endregion
7969
}
8070

8171
public static string GetAbsolutePath(string relativePath)

0 commit comments

Comments
 (0)