static void Main(string[] args) { Dictionary <string, string> customBayesNetStructure = new Dictionary <string, string> { { "class", "" }, { "property_magnitude", "class" }, { "housing", "property_magnitude,class" }, { "purpose", "housing,class" }, { "personal_status", "housing,class" }, { "job", "property_magnitude,class" }, { "employment", "job,class" }, { "own_telephone", "job,class" }, { "credit_history", "own_telephone,class" } }; string trainPath = @"..\..\..\Datasets\example-train.csv"; string testPath = @"..\..\..\Datasets\example-test.csv"; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); // When there is no custom structure for model, it works like a classical bayes classifier BayesNetClassifier model = new BayesNetClassifier(customBayesNetStructure); model.Fit(trainPath, false);// Second boolean parameter is a choice of writing CPT's to file List <string> predictions = model.Predict(testPath); // Classification Report EvaluationMetrics.GetModelReport(predictions, "bad", "good", stopWatch.ElapsedMilliseconds); }
public static void GetModelReport(List <string> predictions, string positiveLabel, string negativeLabel, long elapsedTime) { Dictionary <string, int> conf = EvaluationMetrics.GetConfusionMatrix(BayesNetClassifier.testFeatures[BayesNetClassifier.columns.Count - 1], predictions, "bad", "good"); Dictionary <string, double> metrics = EvaluationMetrics.GetMetrics(conf); Console.WriteLine(String.Format("Elapsed Time: {0} ms", elapsedTime)); Console.WriteLine("Confusion Matrix"); Console.WriteLine("--------------"); Console.WriteLine(String.Format(" {0,-3} {1,-3}\n {2,-3} {3,-3}", conf["TP"], conf["FN"], conf["FP"], conf["TN"])); Console.WriteLine("--------------"); Console.WriteLine(String.Format("TP_Rate: {0}\nTN_Rate: {1}\nAccuracy: {2}", metrics["TP_RATE"], metrics["TN_RATE"], metrics["ACCURACY"])); Console.Read(); }