/// <summary> /// Writes the receiver operating characteristic curve to the file with the specified name. /// </summary> /// <param name="fileName">The name of the file to write the receiver operating characteristic curve to.</param> /// <param name="evaluator">The classifier evaluator.</param> /// <param name="groundTruth">The ground truth.</param> /// <param name="predictiveDistributions">The predictive distributions.</param> /// <param name="positiveClassLabel">The label of the positive class.</param> private void WriteRocCurve( string fileName, ClassifierEvaluator <IList <LabeledFeatureValues>, LabeledFeatureValues, IList <LabelDistribution>, string> evaluator, IList <LabeledFeatureValues> groundTruth, IList <IDictionary <string, double> > predictiveDistributions, string positiveClassLabel) { Debug.Assert(predictiveDistributions != null, "The predictive distributions must not be null."); Debug.Assert(predictiveDistributions.Count > 0, "The predictive distributions must not be empty."); Debug.Assert(positiveClassLabel != null, "The label of the positive class must not be null."); var rocCurve = evaluator.ReceiverOperatingCharacteristicCurve(positiveClassLabel, groundTruth, predictiveDistributions); using (var writer = new StreamWriter(fileName)) { writer.WriteLine("# Receiver operating characteristic (ROC) curve"); writer.WriteLine("#"); writer.WriteLine("# Class '" + positiveClassLabel + "' (versus the rest)"); writer.WriteLine("#"); writer.WriteLine("# False positive rate (FPR), True positive rate (TPR)"); foreach (var point in rocCurve) { writer.WriteLine(point); } } }
/// <summary> /// Writes the receiver operating characteristic curve to the file with the specified name. /// </summary> /// <param name="fileName">The name of the file to write the receiver operating characteristic curve to.</param> /// <param name="evaluator">The classifier evaluator.</param> /// <param name="x">The x vector of the ground truth.</param> /// <param name="y">The y of the ground truth.</param> /// <param name="yPredicDistrib">The predictive distributions.</param> /// <param name="positiveClassLabel">The label of the positive class.</param> /// <remarks>Adapted from MicrosoftResearch.Infer.Learners</remarks> private void WriteRocCurve( string fileName, ClassifierEvaluator <IList <Vector>, int, IList <string>, string> evaluator, Vector[] x, IList <string> y, IEnumerable <IDictionary <string, double> > yPredicDistrib, string positiveClassLabel) { Debug.Assert(yPredicDistrib != null, "The predictive distributions must not be null."); Debug.Assert(yPredicDistrib.Count() > 0, "The predictive distributions must not be empty."); Debug.Assert(positiveClassLabel != null, "The label of the positive class must not be null."); var rocCurve = evaluator.ReceiverOperatingCharacteristicCurve(positiveClassLabel, x, y, yPredicDistrib); using (var writer = new StreamWriter(fileName)) { writer.WriteLine("# Receiver operating characteristic (ROC) curve"); writer.WriteLine("#"); writer.WriteLine("# Class '" + positiveClassLabel + "' (versus the rest)"); writer.WriteLine("#"); writer.WriteLine("# False positive rate (FPR), true positive rate (TPR)"); foreach (var point in rocCurve) { writer.WriteLine("{0}, {1}", point.First, point.Second); } } }