Classify

Classify[{example1class1,example2class2,}]
generates a ClassifierFunction[] based on the examples and classes given.

Classify[{example1,example2,}{class1,class2,}]
generates the same result.

Classify[class1{example11,example12,},class2{example21,},]
generates a ClassifierFunction[] based on an association of classes with their examples.

Classify[training,data]
attempts to classify data using a classifier function deduced from the training set given.

Classify["name",data]
attempts to classify data using the built-in classifier function represented by .

Classify["name",data,prop]
gives the specified property of the classification associated with data.

Details and OptionsDetails and Options

  • Classify works for a variety of data types, including numerical, textual, sound, and image.
  • Each can be a single feature, a list of features, or an association of features. When is a list of features, all must have the same dimensions.
  • Classify[training] returns a ClassifierFunction[] that can then be applied to specific data.
  • In Classify[,data], data can be a single item or a list of items.
  • In Classify[,data,prop], properties are as given in ClassifierFunction[].
  • Examples of built-in classifier functions include:
  • "CountryFlag"which country a flag image is for
    "FacebookTopic"which topic a Facebook post is about
    "Language"which natural language text is in
    "NameGender"which gender a first name is
    "Profanity"whether text contains profanity
    "Sentiment"sentiment of a social media post
    "Spam"whether email is spam
  • The following options can be given:
  • ClassPriorsAutomaticexplicit prior probabilities for classes
    IndeterminateThreshold0below what probability to return Indeterminate
    MethodAutomaticwhich classification algorithm to use
    NominalVariablesAutomaticwhich features should be considered categorical
    PerformanceGoalAutomaticfavor algorithms with specific advantages
    UtilityFunctionAutomaticutility expressed as a function of actual and predicted class
    ValidationSetAutomaticdata on which to validate the generated model
  • Possible settings for PerformanceGoal include:
  • "Memory"minimize the storage requirements of the classifier
    "Quality"maximize the accuracy of the classifier
    "Speed"maximize the speed of the classifier
    "TrainingSpeed"minimize the time spent producing the classifier
  • PerformanceGoal->{goal1,goal2,} will automatically combine , , etc.
  • Possible settings for Method include:
  • "LogisticRegression"classify using probabilities from linear combinations of features
    "Markov"classify using a Markov model of the sequence of features
    "NaiveBayes"classify by assuming probabilistic independence of features
    "NearestNeighbors"classify from nearest-neighbor examples
    "NeuralNetwork"classify using an artificial neural network
    "RandomForest"classify using BreimanCutler ensembles of decision trees
    "SupportVectorMachine"classify using a support vector machine
  • Classify[{assoc1,assoc2,}"key",] can be used to specify that the class is given by the value of in each association .
  • Classify[{list1,list2,}->n,] can be used to specify that the class is given by the value of part n in each list .
  • Classify[Dataset[]part,] can be used to specify that the classes are given by the value of part of each row of the dataset.

ExamplesExamplesopen allclose all

Basic Examples  (2)Basic Examples  (2)

Train a classifier function on labeled examples:

In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=

Use the classifier function to classify a new unlabeled example:

In[3]:=
Click for copyable input
Out[3]=

Obtain classification probabilities for this example:

In[4]:=
Click for copyable input
Out[4]=

Classify multiple examples:

In[5]:=
Click for copyable input
Out[5]=

Plot the probability that the class of an example is as a function of the feature:

In[6]:=
Click for copyable input
Out[6]=

The training and the classification can be performed in one step:

In[7]:=
Click for copyable input
Out[7]=
In[8]:=
Click for copyable input
Out[8]=

Train a classifier with multiple features:

In[1]:=
Click for copyable input
Out[1]=

Classify a new example:

In[2]:=
Click for copyable input
Out[2]=

Classify an example that has missing features:

In[3]:=
Click for copyable input
Out[3]=

Get the probabilities for the most probable classes:

In[4]:=
Click for copyable input
Out[4]=
Introduced in 2014
(10.0)