// add statistics here? // calculate avg, max, min, variation, std, for // should we also calculate stats for each class??? /// <summary> /// Calculate average over all classes and datasets /// </summary> public virtual void calculateStatistics() { average = new ClassificationMetrics.Stats(); // ClassificationMetrics.Stats max = new ClassificationMetrics.Stats(); double count = 0; List <string> classLabels = new List <string>(); // avg max min variation std foreach (EvaluationResult er in results) { ClassificationMetrics[] ccm = er.ClassificationMetricses; foreach (ClassificationMetrics cm in ccm) { average.accuracy += cm.Accuracy; average.precision += cm.Precision; average.recall += cm.Recall; average.fScore += cm.FMeasure; average.mserror += er.MeanSquareError; if (!classLabels.Contains(cm.ClassLabel)) { classLabels.Add(cm.ClassLabel); } } count++; } count = count * classLabels.Count; // * classes count average.accuracy = average.accuracy / count; average.precision = average.precision / count; average.recall = average.recall / count; average.fScore = average.fScore / count; average.mserror = average.mserror / count; }
public static void Main(string[] args) { Evaluation evaluation = new Evaluation(); evaluation.addEvaluator(new ErrorEvaluator(new MeanSquaredError())); string[] classNames = new string[] { "Virginica", "Setosa", "Versicolor" }; MultiLayerPerceptron neuralNet = (MultiLayerPerceptron)NeuralNetwork.createFromFile("irisNet.nnet"); DataSet dataSet = DataSet.createFromFile("data_sets/iris_data_normalised.txt", 4, 3, ","); evaluation.addEvaluator(new ClassifierEvaluator.MultiClass(classNames)); evaluation.evaluateDataSet(neuralNet, dataSet); ClassifierEvaluator evaluator = evaluation.getEvaluator(typeof(ClassifierEvaluator.MultiClass)); ConfusionMatrix confusionMatrix = evaluator.Result; Console.WriteLine("Confusion matrrix:\r\n"); Console.WriteLine(confusionMatrix.ToString() + "\r\n\r\n"); Console.WriteLine("Classification metrics\r\n"); ClassificationMetrics[] metrics = ClassificationMetrics.createFromMatrix(confusionMatrix); ClassificationMetrics.Stats average = ClassificationMetrics.average(metrics); foreach (ClassificationMetrics cm in metrics) { Console.WriteLine(cm.ToString() + "\r\n"); } Console.WriteLine(average.ToString()); }