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"nprobabilities for the n most likely classes
    "Probability"classprobability 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 Automaticexplicit prior probabilities for classes
    IndeterminateThreshold Automaticbelow what probability to return Indeterminate
    MissingValueSynthesisAutomatichow to synthesize missing values
    PerformanceGoalAutomaticwhich aspect of performance to optimize
    TargetDevice "CPU"the target device on which to perform training
    RecalibrationFunction Automatichow to post-process class probabilities
    UtilityFunction Automaticutility 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.


open allclose all

Basic Examples  (2)

Create a ClassifierFunction with Classify and a list of labeled examples:

Classify an unlabeled example with the ClassifierFunction:

Classify multiple examples:

Return the probabilities of the classes given the feature of an example:

Return the sorted probabilities of the most likely classes:

Return the probability of the most probable class:

Return the probability of a given class:

Plot the probability of class "B" as a function of the feature:

Generate a ClassifierFunction using multiple features:

Use the function on a new example:

Classify an example that has missing features:

Get the probabilities for the most probable classes:

Scope  (5)

Create a function classifying textual data:

Classify new examples:

Obtain information on the function:

Obtain the properties that can be used by this function:

Train a classifier function:

Generate a classifier measurements object of the function applied to a test set:

Get the accuracy from the function on the test set:

Visualize the confusion matrix:

Generate a classifier function whose input is an association:

Use the function on an example:

Classify examples containing missing features:

Train a classifier:

Store the ClassifierFunction[] into a file using the "WMLF" format:

Load the classifier from the file using Import:

Use the loaded classifier on new data:

Train a classifier to predict a person's odds of surviving or dying in the Titanic crash:

Calculate the prior odds of a passenger dying:

Use the classifier to predict the odds of a person dying:

Get an explanation of how each feature multiplied the model's predicted odds of a class:

Compare the model's explanation of feature impact to the base rate odds:

Options  (6)

ClassPriors  (1)

Train a classifier on an imbalanced dataset:

The example 5False is classified as True:

Classify this example with a uniform prior over classes:

The class priors of a classifier can also be updated after training:

IndeterminateThreshold  (1)

Train a classifier:

Obtain class probabilities for an example:

The most probable class is chosen as the prediction:

No prediction is made if no class probabilities exceed a specified probability threshold:

Update the value of the threshold permanently:

RecalibrationFunction  (2)

Train a classifier function:

Compute the class probabilities of a new example:

Check if the model has been calibrated:

Temporarily set a recalibration function to apply to the probabilities:

Set a permanent recalibration function to apply to the probabilities:

Compute the class probabilities of a new example:

Remove the recalibration function from the classifier:

Load the Titanic dataset:

Create a nearest neighbors classifier with no calibration function:

The classifier is slightly overconfident:

Select the worst classification case in the test set:

Evaluate the estimated probabilities:

Use "temperature scaling" to reduce the classifier self-confidence:

TargetDevice  (1)

Train a classifier using a neural network:

Evaluate the resulting classifier on system's default GPU and look at its AbsoluteTiming:

Compare the previous timing with the one achieved by using the default CPU computation:

UtilityFunction  (1)

Train a classifier:

By default, the most probable class is predicted:

Specify a utility function that penalizes examples of class "yes" being misclassified as "no":

Update the value of the utility function permanently:

Wolfram Research (2014), ClassifierFunction, Wolfram Language function, (updated 2021).


Wolfram Research (2014), ClassifierFunction, Wolfram Language function, (updated 2021).


Wolfram Language. 2014. "ClassifierFunction." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021.


Wolfram Language. (2014). ClassifierFunction. Wolfram Language & System Documentation Center. Retrieved from


@misc{reference.wolfram_2024_classifierfunction, author="Wolfram Research", title="{ClassifierFunction}", year="2021", howpublished="\url{}", note=[Accessed: 17-July-2024 ]}


@online{reference.wolfram_2024_classifierfunction, organization={Wolfram Research}, title={ClassifierFunction}, year={2021}, url={}, note=[Accessed: 17-July-2024 ]}