How to get the probability/score by each cell/row with machine learning?

Tan, Mei Ting 1 Reputation point
2022-10-25T03:13:05.287+00:00

I have go through the solution in the forum but couldn't find a suitable solution for my question.
I have use machine learning model to get the best algo for data modelling.
I manage to get the confusion table but somehow i looking for probability/scoring for each cell instead of overall result.

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,691 questions
.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
326 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Tan, Mei Ting 1 Reputation point
    2022-10-26T08:03:28.34+00:00

    Below is my coding for Program.cs:

    static void Main(string[] args)
    {
    //testing file location
    string filepath = @"C:\Users\Desktop\Validation_Dataset - ColumnRename.csv";

            CsvConfiguration config = new CsvConfiguration(CultureInfo.InvariantCulture)  
            {  
                PrepareHeaderForMatch = args => args.Header.ToLower(),  
                MissingFieldFound = null  
            };  
    
            int correct = 0;  
            int total = 0;  
    
            using (var reader = new StreamReader(filepath))  
            using (var csv = new CsvReader(reader, config))  
            {  
                csv.Context.RegisterClassMap<PredictionDetailPredictMap>();  
                var records = csv.GetRecords<TrainTest.MLModel1.ModelInput>();  
                StringBuilder sb = new StringBuilder();  
                sb.Append("No,Expected,Predicted,IsMatch");  
                sb.AppendLine();  
                foreach (var record in records)  
                {  
                    try  
                    {  
                        if (record.GB == "0") continue;  
    
                        total++;  
    
                        var result = TrainTest.MLModel1.Predict(record);  
                        Console.WriteLine(record.No);  
                        Console.WriteLine("Expected:" + record.GB);  
                        Console.WriteLine("Predicted:" + result.PredictedLabel);  
                        Console.WriteLine("====================");  
    
                        //if (record.BinRootCause.ToLower() == result.Prediction.ToLower()) correct++;  
    
                        string isMatch = record.GB.ToLower() == result.PredictedLabel.ToLower() ? "YES" : "NO";  
                        if (isMatch == "YES") correct++;  
    
                        sb.Append(record.No + ","  + record.GB + "," + result.PredictedLabel + "," + isMatch + ",");  
                        sb.AppendLine();  
                    }  
                    catch (Exception ex)  
                    {  
                        //store output file path  
                        Console.WriteLine(ex.Message);  
                        File.WriteAllText(@"C:\Desktop\Result\Testing.csv", sb.ToString());  
                    }  
                }  
    
                sb.Append("Accuracy =" + ((float)correct / (float)total) * 100 + "%");  
    
                File.WriteAllText(@"C:\Desktop\Result\Testing.csv", sb.ToString());  
                Console.WriteLine("Accuracy=" + ((float)correct / (float)total) * 100 + "%");  
            }  
        }  
    

    Here is my sample output:
    254176-image.png

    I looking for each cell/row have probability behind, for example:
    254195-image.png

    Do you know how to get the probability for each prediction result?
    Thanks.

    0 comments No comments