RecalibrationFunction
Details
- For classifiers, recalibration is also known as probability calibration and is typically used to correct overconfident or underconfident classifiers.
- RecalibrationFunction can be used at training time, inference time or to update the calibrator of an existing model.
- When specified at inference time or to update the calibrator of an existing model, typical settings for RecalibrationFunction include:
-
None remove existing recalibration f append the function f to the existing calibrator - For classifiers, the function f is applied to the class probabilities f[<|class1p1,class2p2,…|>] and should return new class probabilities. New class probabilities are automatically normalized.
- For predictors, the function f transforms the predictive distribution by being applied to the output values.
- When specified at training time, typical settings for RecalibrationFunction include:
-
None prevent any recalibration Automatic recalibrate the model when needed All always recalibrate the model - Besides being used on the final model, recalibration is also applied to candidate models generated by Classify and Predict during their training procedure.
- When RecalibrationFunctionAll, recalibration is applied to every candidate model.
- When RecalibrationFunctionAutomatic, recalibration is only used for candidate models that need it.
Examples
open all close allBasic Examples (2)
Train a classifier without any recalibration:
c = Classify[{1 -> "A", 2 -> "A", 3.5 -> "B", 3.7 -> "A", 4 -> "B", 5.5 -> "B"}, RecalibrationFunction -> None]Compute the class probabilities of a new example:
c[3, "Probabilities"]Temporarily set a recalibration function to apply to the probabilities:
c[3, "Probabilities", RecalibrationFunction -> Sqrt]Train a predictor without any recalibration:
p = Predict[{1 -> 1.3, 2 -> 2.4, 3 -> 4.4, 4 -> 5.1, 6 -> 7.3}, RecalibrationFunction -> None]Compute the predictive distribution:
p[3.4, "Distribution"]Compute the predictive distribution with a temporary set recalibration function:
p[3.4, "Distribution", RecalibrationFunction -> (.5# + 0.1&)]Scope (12)
Training (6)
Train a ClassifierFunction with recalibration if needed (default):
c = Classify[{1 -> "A", 2 -> "A", 3.5 -> "B", 3.7 -> "A", 4 -> "B", 5.5 -> "B"}, Method -> "RandomForest", RecalibrationFunction -> Automatic]Check if the model has been calibrated:
Information[c, "Calibrated"]Compute the class probabilities of a new example:
c[1.5, "Probabilities"]Compare with the raw random forest model probabilities:
c[1.5, "Probabilities", RecalibrationFunction -> None]Train a ClassifierFunction with no recalibration:
c = Classify[{1 -> "A", 2 -> "A", 3.5 -> "B", 3.7 -> "A", 4 -> "B", 5.5 -> "B"}, Method -> "RandomForest", RecalibrationFunction -> None]Train a ClassifierFunction with mandatory recalibration:
c = Classify[{1 -> "A", 2 -> "A", 3.5 -> "B", 3.7 -> "A", 4 -> "B", 5.5 -> "B"}, Method -> "LogisticRegression", RecalibrationFunction -> All]Compute the class probabilities of a new example:
c[1.5, "Probabilities"]Compare with the raw logistic regression model probabilities:
c[1.5, "Probabilities", RecalibrationFunction -> None]Train a PredictorFunction with recalibration if needed (default):
p = Predict[{0 -> 0.94, 0.10 -> 0.67, 0.20 -> 0.60, 0.30 -> 0.47, 0.40 -> 0.41, 0.50 -> 1.2, 0.60 -> 0.87, 0.70 -> 1.5, 0.80 -> 1.8, 0.90 -> 1.9, 1.0 -> 1.2, 1.1 -> 1.5, 1.2 -> 1.9, 1.3 -> 1.5, 1.4 -> 1.7, 1.5 -> 2.3, 1.6 -> 2.0, 1.7 -> 2.2, 1.8 -> 2.0, 1.9 -> 2.8, 2.0 -> 2.7, 2.1 -> 2.5, 2.2 -> 2.6, 2.3 -> 2.7, 2.4 -> 2.5, 2.5 -> 3.1, 2.6 -> 2.6, 2.7 -> 2.9, 2.8 -> 3.0, 2.9 -> 3.7, 3.0 -> 3.4, 3.1 -> 4.0, 3.2 -> 3.9, 3.3 -> 4.3, 3.4 -> 4.0, 3.5 -> 4.0, 3.6 -> 4.1, 3.7 -> 4.1, 3.8 -> 4.5, 3.9 -> 4.4, 4.0 -> 4.2, 4.1 -> 4.9, 4.2 -> 5.2, 4.3 -> 4.4, 4.4 -> 4.4, 4.5 -> 5.1, 4.6 -> 5.1, 4.7 -> 5.3, 4.8 -> 5.1, 4.9 -> 5.4, 5.0 -> 5.9}, Method -> "LinearRegression", RecalibrationFunction -> Automatic]Check if the model has been calibrated:
Information[p, "Calibrated"]Compute the class probabilities of a new example:
p[2.5, "Distribution"]Train a PredictorFunction with no recalibration:
p = Predict[{0 -> 0.94, 0.10 -> 0.67, 0.20 -> 0.60, 0.30 -> 0.47, 0.40 -> 0.41, 0.50 -> 1.2, 0.60 -> 0.87, 0.70 -> 1.5, 0.80 -> 1.8, 0.90 -> 1.9, 1.0 -> 1.2, 1.1 -> 1.5, 1.2 -> 1.9, 1.3 -> 1.5, 1.4 -> 1.7, 1.5 -> 2.3, 1.6 -> 2.0, 1.7 -> 2.2, 1.8 -> 2.0, 1.9 -> 2.8, 2.0 -> 2.7, 2.1 -> 2.5, 2.2 -> 2.6, 2.3 -> 2.7, 2.4 -> 2.5, 2.5 -> 3.1, 2.6 -> 2.6, 2.7 -> 2.9, 2.8 -> 3.0, 2.9 -> 3.7, 3.0 -> 3.4, 3.1 -> 4.0, 3.2 -> 3.9, 3.3 -> 4.3, 3.4 -> 4.0, 3.5 -> 4.0, 3.6 -> 4.1, 3.7 -> 4.1, 3.8 -> 4.5, 3.9 -> 4.4, 4.0 -> 4.2, 4.1 -> 4.9, 4.2 -> 5.2, 4.3 -> 4.4, 4.4 -> 4.4, 4.5 -> 5.1, 4.6 -> 5.1, 4.7 -> 5.3, 4.8 -> 5.1, 4.9 -> 5.4, 5.0 -> 5.9}, Method -> "LinearRegression", RecalibrationFunction -> None]Train a PredictorFunction with mandatory recalibration:
p = Predict[{0 -> 0.94, 0.10 -> 0.67, 0.20 -> 0.60, 0.30 -> 0.47, 0.40 -> 0.41, 0.50 -> 1.2, 0.60 -> 0.87, 0.70 -> 1.5, 0.80 -> 1.8, 0.90 -> 1.9, 1.0 -> 1.2, 1.1 -> 1.5, 1.2 -> 1.9, 1.3 -> 1.5, 1.4 -> 1.7, 1.5 -> 2.3, 1.6 -> 2.0, 1.7 -> 2.2, 1.8 -> 2.0, 1.9 -> 2.8, 2.0 -> 2.7, 2.1 -> 2.5, 2.2 -> 2.6, 2.3 -> 2.7, 2.4 -> 2.5, 2.5 -> 3.1, 2.6 -> 2.6, 2.7 -> 2.9, 2.8 -> 3.0, 2.9 -> 3.7, 3.0 -> 3.4, 3.1 -> 4.0, 3.2 -> 3.9, 3.3 -> 4.3, 3.4 -> 4.0, 3.5 -> 4.0, 3.6 -> 4.1, 3.7 -> 4.1, 3.8 -> 4.5, 3.9 -> 4.4, 4.0 -> 4.2, 4.1 -> 4.9, 4.2 -> 5.2, 4.3 -> 4.4, 4.4 -> 4.4, 4.5 -> 5.1, 4.6 -> 5.1, 4.7 -> 5.3, 4.8 -> 5.1, 4.9 -> 5.4, 5.0 -> 5.9}, Method -> "LinearRegression", RecalibrationFunction -> All]Compute the probability distribution for a new example:
p[2.5, "Distribution"]Compare with the raw logistic regression model probabilities:
p[2.5, "Distribution", RecalibrationFunction -> None]Inference (6)
Compute the class probabilities of a example without recalibration:
ClassifierFunction[Association["ExampleNumber" -> 6, "ClassNumber" -> 2,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
... e" -> DateObject[{2026, 2, 12, 15, 32,
46.896995`8.423719992106033}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]][1.5, "Probabilities", RecalibrationFunction -> None]Use the build in recalibration function:
ClassifierFunction[Association["ExampleNumber" -> 6, "ClassNumber" -> 2,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
... e" -> DateObject[{2026, 2, 12, 15, 32,
46.896995`8.423719992106033}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]][1.5, "Probabilities"]Temporarily set a custom recalibration function after the classifier built-in one:
ClassifierFunction[Association["ExampleNumber" -> 6, "ClassNumber" -> 2,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
... e" -> DateObject[{2026, 2, 12, 15, 32,
46.896995`8.423719992106033}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]][1.5, "Probabilities", RecalibrationFunction -> Sqrt]Obtain a new ClassifierFunction with a removed calibration:
c = Classify[ClassifierFunction[Association["ExampleNumber" -> 6, "ClassNumber" -> 2,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
... e" -> DateObject[{2026, 2, 12, 15, 32,
46.896995`8.423719992106033}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]], RecalibrationFunction -> None]Information[c, "Calibrated"]Obtain a new ClassifierFunction appending a custom function to the calibrator:
c = Classify[ClassifierFunction[Association["ExampleNumber" -> 6, "ClassNumber" -> 2,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
... e" -> DateObject[{2026, 2, 12, 15, 32,
46.896995`8.423719992106033}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]], RecalibrationFunction -> Sqrt]Compute the predicted probability distribution for an example without recalibration:
PredictorFunction[Association["ExampleNumber" -> 51,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
"Output" -> A ... te" -> DateObject[{2026, 2, 12, 16, 9,
21.546464`8.085950991511702}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]][2.5, "Distribution", RecalibrationFunction -> None]Use the PredictorFunction built-in recalibration function:
PredictorFunction[Association["ExampleNumber" -> 51,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
"Output" -> A ... te" -> DateObject[{2026, 2, 12, 16, 9,
21.546464`8.085950991511702}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]][2.5, "Distribution"]Temporarily set a custom recalibration function after the PredictorFunction built-in one:
PredictorFunction[Association["ExampleNumber" -> 51,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
"Output" -> A ... te" -> DateObject[{2026, 2, 12, 16, 9,
21.546464`8.085950991511702}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]][2.5, "Distribution", RecalibrationFunction -> (.5# + 0.1&)]Obtain a new PredictorFunction with a removed calibration:
p = Predict[PredictorFunction[Association["ExampleNumber" -> 51,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
"Output" -> A ... te" -> DateObject[{2026, 2, 12, 16, 9,
21.546464`8.085950991511702}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]], RecalibrationFunction -> None]Information[p, "Calibrated"]Obtain a new PredictorFunction appending a custom function to the calibrator:
p = Predict[PredictorFunction[Association["ExampleNumber" -> 51,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
"Output" -> A ... te" -> DateObject[{2026, 2, 12, 16, 9,
21.546464`8.085950991511702}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]], RecalibrationFunction -> (.5# + 0.1&)]Applications (3)
MNIST (1)
training = RandomSample[ResourceData["MNIST", "TrainingData"], 1000];
test = ResourceData["MNIST", "TestData"];Train a random forest classifier without any recalibration:
c = Classify[training, Method -> "RandomForest", RecalibrationFunction -> None]Visualize the calibration curve on a test set:
ClassifierMeasurements[c, test, "CalibrationCurve"]Train a random forest classifier with recalibration:
c2 = Classify[training, Method -> "RandomForest", RecalibrationFunction -> All]Visualize the calibration curve on a test set:
ClassifierMeasurements[c2, test, "CalibrationCurve"]Titanic (1)
train = ExampleData[{"MachineLearning", "Titanic"}, "TrainingData"];
test = ExampleData[{"MachineLearning", "Titanic"}, "TestData"];Train a nearest neighbors classifier with no calibration function:
c = Classify[train, Method -> "NearestNeighbors", RecalibrationFunction -> None]The classifier is slightly overconfident:
ClassifierMeasurements[c, test, "CalibrationCurve"]Select the worst classification case in the test set:
badcase = First@ClassifierMeasurements[c, test, "WorstClassifiedExamples" -> 1]Evaluate the estimated probabilities:
c[badcase[[1]], "Probabilities"]Use "temperature scaling" to reduce the classifier self-confidence:
c[badcase[[1]], "Probabilities", RecalibrationFunction -> (# ^ .8&)]ClassifierMeasurements[Classify[c, RecalibrationFunction -> (# ^ .8&)], test, "CalibrationCurve"]Boston Homes (1)
Load the Boston Homes dataset:
training = RandomSample[ResourceData["Sample Data: Boston Homes", "TrainingData"]];
test = ResourceData["Sample Data: Boston Homes", "TestData"];Train a predictor with model calibration:
p = Predict[training, Method -> "RandomForest", RecalibrationFunction -> All]Visualize the comparison plot on a test set:
PredictorMeasurements[p, test, "ComparisonPlot"]Remove the recalibration function from the predictor:
p2 = Predict[p, RecalibrationFunction -> None]Visualize the new comparison plot:
PredictorMeasurements[p2, test, "ComparisonPlot"]Properties & Relations (2)
In ClassifierFunction, RecalibrationFunction is equivalent to renormalized probabilities:
ClassifierFunction[Association["ExampleNumber" -> 6, "ClassNumber" -> 2,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
... e" -> DateObject[{2026, 2, 12, 15, 32,
46.896995`8.423719992106033}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]][1.5, "Probabilities", RecalibrationFunction -> Sqrt]Normalize[Sqrt[ClassifierFunction[Association["ExampleNumber" -> 6, "ClassNumber" -> 2,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
... e" -> DateObject[{2026, 2, 12, 15, 32,
46.896995`8.423719992106033}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]][1.5, "Probabilities"]], Total]In PredictorFunction, RecalibrationFunction is equivalent to TransformedDistribution action:
PredictorFunction[Association["ExampleNumber" -> 51,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
"Output" -> A ... te" -> DateObject[{2026, 2, 12, 16, 25,
4.411868`7.397197498244802}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]][1.5, "Distribution", RecalibrationFunction -> (.5# + 0.1&)]TransformedDistribution[.5x + 0.1, xPredictorFunction[Association["ExampleNumber" -> 51,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
"Output" -> A ... te" -> DateObject[{2026, 2, 12, 16, 25,
4.411868`7.397197498244802}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]][1.5, "Distribution"]]Related Guides
History
Text
Wolfram Research (2021), RecalibrationFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/RecalibrationFunction.html.
CMS
Wolfram Language. 2021. "RecalibrationFunction." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RecalibrationFunction.html.
APA
Wolfram Language. (2021). RecalibrationFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RecalibrationFunction.html
BibTeX
@misc{reference.wolfram_2026_recalibrationfunction, author="Wolfram Research", title="{RecalibrationFunction}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/RecalibrationFunction.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_recalibrationfunction, organization={Wolfram Research}, title={RecalibrationFunction}, year={2021}, url={https://reference.wolfram.com/language/ref/RecalibrationFunction.html}, note=[Accessed: 13-June-2026]}