ML.NET.Classification.Metrics 0.1.4

dotnet add package ML.NET.Classification.Metrics --version 0.1.4
                    
NuGet\Install-Package ML.NET.Classification.Metrics -Version 0.1.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ML.NET.Classification.Metrics" Version="0.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ML.NET.Classification.Metrics" Version="0.1.4" />
                    
Directory.Packages.props
<PackageReference Include="ML.NET.Classification.Metrics" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ML.NET.Classification.Metrics --version 0.1.4
                    
#r "nuget: ML.NET.Classification.Metrics, 0.1.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ML.NET.Classification.Metrics@0.1.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ML.NET.Classification.Metrics&version=0.1.4
                    
Install as a Cake Addin
#tool nuget:?package=ML.NET.Classification.Metrics&version=0.1.4
                    
Install as a Cake Tool

ML.NET Classification Metrics: ROC Curve & AUC

About

ML.NET.Classification.Metrics is an unofficial library for ML.NET that adds detailed ROC curve generation and AUC calculation, complementing ML.NET’s built-in metrics with richer visualization and clearer threshold analysis.

Key Features

  • ROC curve (Exact): Generates ROC points for every unique score threshold, with tied scores grouped, plus endpoints, giving the most accurate ROC curve and AUC.
  • ROC curve (Binned): Sweeps thresholds from 1.0 to 0.0 using (buckets + 1) steps for a fast, fixed-size approximation (best when inputs are probabilities in [0,1])
  • Custom buckets: Choose bucket count in Binned mode to trade curve detail for speed.
  • Consistent AUC: Computes AUC via trapezoidal integration over the same ROC points, so the curve and AUC always match.
  • Threshold visibility: Each ROC point includes its threshold, making cutoff analysis (TPR/FPR changes) straightforward.
  • Interop-ready: Returns strongly-typed .NET structs, making results easy to visualize in charts and diagnostics tools.

Library Guide

EvaluateRoc builds a ROC curve by sorting samples by score and simulating different decision thresholds, expecting:

  • scores (float[]): a ranking signal where higher values mean “more likely positive”
  • labels (bool[]): ground truth labels (true = positive, false = negative)

Important: scores[] and labels[] must be aligned (same row order, same length).

  • Use Probability when available (calibrated in [0,1]). Otherwise use Score and set clampScoresToUnitInterval: false.

Logistic Regression: prepare scores and labels (ensure the correct label column name)

public sealed class BinaryPrediction
{
    public float Probability { get; set; } // Logistic Regression: in [0,1]
}

public sealed class LabelRow
{
    public bool Label { get; set; }
}

var predictions = model.Transform(testData);

float[] scores = mlContext.Data
    .CreateEnumerable<BinaryPrediction>(predictions, reuseRowObject: false)
    .Select(r => r.Probability)
    .ToArray();

bool[] labels = mlContext.Data
    .CreateEnumerable<LabelRow>(testData, reuseRowObject: false)
    .Select(r => r.Label)
    .ToArray();

Example A: Exact ROC (recommended)

  • Use Exact mode for the most accurate ROC curve and AUC (one point per unique threshold + endpoints).

    var rocExact = CoreMetricsEvaluator.EvaluateRoc( scores: scores, labels: labels, mode: RocMode.Exact, clampScoresToUnitInterval: true );

double auc = rocExact.Score; var points = rocExact.Points; // ROC points

Example B: Binned ROC (fast approximation)

  • Use Binned mode for a fast, fixed-size ROC curve: thresholds sweep from 1.0 → 0.0 using (buckets + 1) steps.

  • Binned mode assumes scores are in [0,1] (or set clampScoresToUnitInterval: true).

    var rocBinned = CoreMetricsEvaluator.EvaluateRoc( scores: scores, labels: labels, mode: RocMode.Binned, buckets: 200, clampScoresToUnitInterval: true );

EvaluateRoc returns a MetricsCurve<RocPoint>:

  • roc.Score → the AUC

  • roc.Points → ROC points containing:

    • Fpr (False Positive Rate)
    • Tpr (True Positive Rate)
    • Threshold (the cutoff used for that point)

NuGet package

  1. Add the NuGet package:
  • dotnet add package ML.NET.Classification.Metrics --version 0.1.2
  1. Import the namespace in your code
  • using ML.NET.Metrics.Evaluation.Public;

Libraries

  • .NET 8.0
  • Windows x64 native binary
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.4 94 2/5/2026
0.1.2 93 2/4/2026
0.1.1 90 2/4/2026