represents a function generated by Classify that classifies data into classes.
ClassifierFunction
represents a function generated by Classify that classifies data into classes.
Details and Options
- ClassifierFunction works like Function.
- ClassifierFunction[…][data] attempts to classify data, returning the class in which data is considered most likely to be.
- ClassifierFunction[…][{data1,data2,…}] attempts to classify all the datai.
- ClassifierFunction[…][data,prop] gives the specified property of the classification associated with data.
- Possible properties applicable to all methods include:
-
"Decision" best class according to the probabilities and the utility function "TopProbabilities" probabilities for most likely classes "TopProbabilities"n probabilities for the n most likely classes "Probability"class probability for a specific class "Probabilities" association of probabilities for all possible classes "SHAPValues" Shapley additive feature explanations for each example "Properties" list of all properties available - "SHAPValues" assesses the contribution of features by comparing predictions with different sets of features removed and then synthesized. The option MissingValueSynthesis can be used to specify how the missing features are synthesized. SHAP explanations are given as odds ratio multipliers with respect to the class training prior. "SHAPValues"n can be used to control the number of samples used for the numeric estimations of SHAP explanations.
- ClassifierFunction[…][data,…,opts] specifies that the classifier should use the options opts when applied to data.
- Possible options are:
-
ClassPriors Automatic explicit prior probabilities for classes IndeterminateThreshold Automatic below what probability to return Indeterminate MissingValueSynthesis Automatic how to synthesize missing values PerformanceGoal Automatic which aspect of performance to optimize TargetDevice "CPU" the target device on which to perform training RecalibrationFunction Automatic how to post-process class probabilities UtilityFunction Automatic utility expressed as a function of actual and predicted class - A ClassifierFunction[…] trained in an older version of the Wolfram Language will still work in the current version.
- Classify[net] can be used to convert a NetChain or NetGraph representing a classifier into a ClassifierFunction[…].
- Classify[ClassifierFunction[…],opts], can be used to update the values of PerformanceGoal, ClassPriors, IndeterminateThreshold, UtilityFunction or FeatureExtractor of the classifier.
- In Classify[ClassifierFunction[…],FeatureExtractorfe], the FeatureExtractorFunction[…] fe will be prepended to the existing feature extractor.
- Information[ClassifierFunction[…]] generates an information panel about the classifier and its estimated performances.
- Information[ClassifierFunction[…],prop] can be used to obtain specific properties.
- Information of a ClassifierFunction may include the following properties:
-
"Accuracy" estimated accuracy of the classifier "BatchEvaluationTime" marginal time to predict one example when a batch is given "Classes" list of classes that the classifier can return "ClassNumber" number of classes that the classifier can return "EvaluationTime" time needed to classify one example "ExampleNumber" number of training examples "FeatureTypes" feature types of the classfier input "FunctionMemory" memory needed to store the classifier "FunctionProperties" all classification properties available for this classifier "IndeterminateThreshold" value of IndeterminateThreshold used by the classifier "LearningCurve" performance as a function of the training set size "MaxTrainingMemory" maximum memory used during training "MeanCrossEntropy" estimated mean cross entropy of the classifier "Method" value of Method used by the classifier "MethodDescription" summary of the method "MethodOption" full method option to be reused in a new training "MethodParameters" parameter settings of the method "Properties" all information properties available for this classifier "FeatureExtractor" feature extractor as FeatureExtractorFunction "TrainingClassPriors" the distribution of classes seen during training "TrainingTime" time used by Classify to generate the classifier "UtilityFunction" value of UtilityFunction used by the classifier - Information properties also include all method suboptions.
Examples
open all close allBasic Examples (2)
Create a ClassifierFunction with Classify and a list of labeled examples:
c = Classify[{1 -> "A", 2 -> "A", 3 -> "B", 4 -> "B", 5 -> "C", 6 -> "C"}]Classify an unlabeled example with the ClassifierFunction:
c[1.5]c[{-3, 1.5, 4.1, 7, 10}]Generate a ClassifierFunction using multiple features:
c = Classify[{
{1.5, "blue"} -> "a", {3.2, "blue"} -> "a", {4.1, "red"} -> "b", {5.3, "red"} -> "b", {10., "green"} -> "c", {12.4, "red"} -> "c"}]Use the function on a new example:
c[{10.1, "blue"}]Classify an example that has missing features:
c[{10.1, Missing[]}]Get the probabilities for the most probable classes:
c[{10.1, "blue"}, "TopProbabilities"]Scope (10)
Create a ClassifierFunction with Classify and a list of labeled examples:
c = Classify[{1 -> "A", 2 -> "A", 3 -> "B", 4 -> "B", 5 -> "C", 6 -> "C"}]Return the probabilities of the classes given the feature of an example:
c[2.55, "Probabilities"]Return the sorted probabilities of the most likely classes:
ClassifierFunction[Association["ExampleNumber" -> 6, "ClassNumber" -> 3,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
... ate" -> DateObject[{2026, 1, 21, 16, 48,
1.00981`6.756814656022382}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]][2.55, "TopProbabilities"]Return the probability of the most probable class:
ClassifierFunction[Association["ExampleNumber" -> 6, "ClassNumber" -> 3,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
... ate" -> DateObject[{2026, 1, 21, 16, 48,
1.00981`6.756814656022382}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]][2.55, {"TopProbabilities", 1}]Return the probability of a given class:
ClassifierFunction[Association["ExampleNumber" -> 6, "ClassNumber" -> 3,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
... ate" -> DateObject[{2026, 1, 21, 16, 48,
1.00981`6.756814656022382}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]][2.55, {"Probability", "C"}]Plot the probability of class "B" as a function of the feature:
Plot[ClassifierFunction[Association["ExampleNumber" -> 6, "ClassNumber" -> 3,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]],
... ate" -> DateObject[{2026, 1, 21, 16, 48,
1.00981`6.756814656022382}, "Instant", "Gregorian", 1.], "ProcessorCount" -> 4,
"ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]][x, "Probability" -> "B"], {x, 0, 7}, Exclusions -> None]Create a function classifying textual data:
c = Classify[{"the cat is grey" -> [image], "my cat is cute" -> [image], "this dog is scary" -> [image] , "the big dog" -> [image]}]c[{"nice cat", "what a dog"}]Obtain information on the function:
Information[c]Obtain the properties that can be used by this function:
Information[c, "FunctionProperties"]c = Classify[{1, 2, 3.5, 4, 5} -> {"A", "A", "A", "B", "B"}]Generate a classifier measurements object of the function applied to a test set:
cm = ClassifierMeasurements[c, {1.4 -> "A", 5.3 -> "B", 1.2 -> "B", 4.6 -> "B", -3 -> "A"}]Get the accuracy from the function on the test set:
cm["Accuracy"]Visualize the confusion matrix:
cm["ConfusionMatrixPlot"]Generate a classifier function whose input is an association:
c = Classify[{
<|"Age" -> 32, "Height" -> 160|> -> "Female",
<|"Height" -> 183, "Age" -> 41|> -> "Male",
<|"Height" -> 123|> -> "Female",
<|"Height" -> 175, "Age" -> 21|> -> "Male",
<|"Age" -> 11|> -> "Male",
<|"Age" -> 52, "Height" -> 164|> -> "Female"}]Use the function on an example:
c[<|"Age" -> 12, "Height" -> 120|>]Classify examples containing missing features:
c[{<|"Height" -> 190|>, <|"Age" -> 90|>, <|"Height" -> 160|>, <||>}]c = Classify[{1 -> "A", 2 -> "A", 3 -> "B", 4 -> "B", 5 -> "C", 6 -> "C"}]Store the ClassifierFunction[…] into a file using the "WMLF" format:
file = File[FileNameJoin[{$TemporaryDirectory, "classifier.wmlf"}]]File["/private/var/folders/6p/lqd9zmn914x_dk57_3d_4wth000cjj/T/classifier.wmlf"]Export[file, c]Load the classifier from the file using Import:
c2 = Import[file]Use the loaded classifier on new data:
c2[1.6]c2[1.6, "Probabilities"]Train a classifier to predict a person's odds of surviving or dying in the Titanic crash:
titanic = ResourceData["Sample Data: Titanic Survival"];
c = Classify[titanic -> "SurvivalStatus", Method -> "NearestNeighbors"]Calculate the prior odds of a passenger dying:
baseProbability = Information[c, "TrainingClassPriors"]["died"];
priorOdds = baseProbability / (1 - baseProbability)Use the classifier to predict the odds of a person dying:
dyingProb = c[{"1st", Quantity[80, "Years"], "male"}, "Probability" -> "died"];
dyingOdds = dyingProb / (1 - dyingProb)Get an explanation of how each feature multiplied the model's predicted odds of a class:
shaps = c[{"1st", Quantity[80, "Years"], "male"}, "SHAPValues"]["died"]Compare the model's explanation of feature impact to the base rate odds:
priorOdds * shaps["Class"] * shaps["Age"] * shaps["Sex"]
priorOdds * shaps["Class"] * shaps["Age"] * shaps["Sex"] == dyingOddsOptions (8)
AcceptanceThreshold (1)
Create a classifier and specify that an anomaly detector should be included:
c = Classify[{1 -> "A", 2 -> "A", 3.5 -> "B", 4 -> "B"}, AnomalyDetector -> Automatic]Change the value of the acceptance threshold when evaluating the classifier:
c[6, AcceptanceThreshold -> 0.01]c[6, AcceptanceThreshold -> 0.0001]Permanently change the value of the acceptance threshold in the classifier:
c2 = Classify[c, AcceptanceThreshold -> 0.01]c2[6, AcceptanceThreshold -> 0.01]AnomalyDetector (1)
Create a classifier and specify that an anomaly detector should be included:
c = Classify[{1 -> "A", 2 -> "A", 3.5 -> "B", 4 -> "B"}, AnomalyDetector -> Automatic]Evaluate the classifier on a non-anomalous input:
c[1.2]Evaluate the classifier on an anomalous input:
c[100000.2]The "Probabilities" property is not affected by the anomaly detector:
c[100000.2, "Probabilities"]Temporarily remove the anomaly detector from the classifier:
c[10000.2, AnomalyDetector -> None]Permanently remove the anomaly detector from the classifier:
c2 = Classify[c, AnomalyDetector -> None]c2[10000.2]ClassPriors (1)
Train a classifier on an imbalanced dataset:
data = {1 -> True, 2 -> True, 3 -> True, 4 -> True, 5 -> False, 6 -> True};c = Classify[data, Method -> "LogisticRegression"]The example 5False is classified as True:
c[5]c[5, "Probabilities"]Classify this example with a uniform prior over classes:
c[5, ClassPriors -> <|False -> 0.5, True -> 0.5|>]c[5, "Probabilities", ClassPriors -> <|False -> 0.5, True -> 0.5|>]The class priors of a classifier can also be updated after training:
c2 = Classify[c, ClassPriors -> <|False -> 0.5, True -> 0.5|>]c2[5, "Probabilities"]IndeterminateThreshold (1)
data = {1 -> "B", 2 -> "B", 3 -> "A", 4 -> "B", 5 -> "A", 6 -> "A"};c = Classify[data]Obtain class probabilities for an example:
c[3, "Probabilities"]The most probable class is chosen as the prediction:
c[3]No prediction is made if no class probabilities exceed a specified probability threshold:
c[5, IndeterminateThreshold -> 0.9]Update the value of the threshold permanently:
c2 = Classify[c, IndeterminateThreshold -> 0.9]c2[5]RecalibrationFunction (2)
c = Classify[{1 -> "A", 2 -> "A", 3.5 -> "B", 3.7 -> "A", 4 -> "B", 5.5 -> "B"}]Compute the class probabilities of a new example:
c[3, "Probabilities"]Check if the model has been calibrated:
Information[c, "Calibrated"]Temporarily set a recalibration function to apply to the probabilities:
c[3, "Probabilities", RecalibrationFunction -> Sqrt]Set a permanent recalibration function to apply to the probabilities:
c2 = Classify[c, RecalibrationFunction -> Sqrt]Compute the class probabilities of a new example:
c2[3, "Probabilities"]Remove the recalibration function from the classifier:
Classify[c, RecalibrationFunction -> Sqrt]train = ExampleData[{"MachineLearning", "Titanic"}, "TrainingData"];
test = ExampleData[{"MachineLearning", "Titanic"}, "TestData"];Create 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 -> (Exp[Log[# + 10 ^ -6] * .9]&)]ClassifierMeasurements[Classify[c, RecalibrationFunction -> (Exp[Log[# + 10 ^ -6] * .9]&)], test, "CalibrationCurve"]TargetDevice (1)
Train a classifier using a neural network:
trainingData = RandomReal[1, {2000, 4}] -> RandomChoice[{"a", "b", "c", "d"}, 2000];
classifier = Classify[trainingData, Method -> "NeuralNetwork", TargetDevice -> "GPU"]Evaluate the resulting classifier on system's default GPU and look at its AbsoluteTiming:
n = 10000
AbsoluteTiming[classifier[RandomReal[1, {n, 4}], TargetDevice -> "GPU"];]Compare the previous timing with the one achieved by using the default CPU computation:
AbsoluteTiming[classifier[RandomReal[1, {n, 4}]];]UtilityFunction (1)
trainingset = {1, 2, 3, 4} -> {"yes", "yes", "no", "no"};c = Classify[trainingset]By default, the most probable class is predicted:
c[2.55, "Probabilities"]c[2.55]Specify a utility function that penalizes examples of class "yes" being misclassified as "no":
c[2.55, UtilityFunction -> <|"no" -> <|"no" -> 1, "yes" -> 0|>, "yes" -> <|"no" -> -100, "yes" -> 1|> |>]Update the value of the utility function permanently:
c2 = Classify[c, UtilityFunction -> <|"no" -> <|"no" -> 1, "yes" -> 0|>, "yes" -> <|"no" -> -100, "yes" -> 1|> |>]c[2.55]Related Guides
History
Introduced in 2014 (10.0) | Updated in 2017 (11.1) ▪ 2018 (11.3) ▪ 2019 (12.0) ▪ 2021 (12.3)
Text
Wolfram Research (2014), ClassifierFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/ClassifierFunction.html (updated 2021).
CMS
Wolfram Language. 2014. "ClassifierFunction." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/ClassifierFunction.html.
APA
Wolfram Language. (2014). ClassifierFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ClassifierFunction.html
BibTeX
@misc{reference.wolfram_2026_classifierfunction, author="Wolfram Research", title="{ClassifierFunction}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/ClassifierFunction.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_classifierfunction, organization={Wolfram Research}, title={ClassifierFunction}, year={2021}, url={https://reference.wolfram.com/language/ref/ClassifierFunction.html}, note=[Accessed: 13-June-2026]}