Enumeration

MLClassifier

A model you train to classify data into discrete categories.

Declaration

enum MLClassifier

Overview

Use an MLClassifier to train a general-purpose model to recognize categories.

For example, you can create a classifier that predicts whether a sports team is likely to win or lose its next game by training it with these inputs:

  • The team’s win-loss ratio

  • The team’s game locations

When you create an MLClassifier, Create ML inspects your data and automatically chooses a specific classifier (see Supporting Classifier Types).

Topics

Creating and Training a Classifier

init(trainingData: MLDataTable, targetColumn: String, featureColumns: [String]?)

Creates a classifier from the feature columns in the training data to predict the categories in the target column.

var targetColumn: String

The name of the column you selected at initialization to define which categories the classifier predicts.

var featureColumns: [String]

The names of the columns you selected at initialization to train the classifier.

Assessing Model Accuracy

var trainingMetrics: MLClassifierMetrics

Measurements of the classifier’s performance on the training data set.

var validationMetrics: MLClassifierMetrics

Measurements of the classifier’s performance on the validation data set.

Evaluating a Classifier

func evaluation(on: MLDataTable) -> MLClassifierMetrics

Returns metrics describing the classifier’s performance on the provided labeled data.

Testing a Classifier

func predictions(from: MLDataTable) -> MLUntypedColumn

Classifies the provided data into the target categories.

Saving a Classifier

func write(to: URL, metadata: MLModelMetadata?)

Exports a Core ML model file for use in your app.

func write(toFile: String, metadata: MLModelMetadata?)

Exports a Core ML model file for use in your app.

Describing a Model

var model: MLModel

The underlying Core ML model stored in memory.

var description: String

A text representation of the classifier.

var debugDescription: String

A text representation of the classifier that’s suitable for output during debugging.

var playgroundDescription: Any

A description of the classifier shown in a playground.

Classifier Cases

The classifier case that is chosen automatically when you initialize an MLClassifier.

case decisionTree(MLDecisionTreeClassifier)

A classifier that predicts the target by creating rules to split the data.

case randomForest(MLRandomForestClassifier)

A classifier based on a collection of decision trees trained on subsets of the data.

case boostedTree(MLBoostedTreeClassifier)

A classifier based on a collection of decision trees combined with gradient boosting.

case logisticRegression(MLLogisticRegressionClassifier)

A classifier that predicts a discrete target value as a function of data features.

case supportVector(MLSupportVectorClassifier)

A classifier that predicts a binary target value by maximizing the separation between categories.

Supporting Classifier Types

struct MLDecisionTreeClassifier

A classifier that predicts the target by creating rules to split the data.

struct MLRandomForestClassifier

A classifier based on a collection of decision trees trained on subsets of the data.

struct MLBoostedTreeClassifier

A classifier based on a collection of decision trees combined with gradient boosting.

struct MLLogisticRegressionClassifier

A classifier that predicts a discrete target value as a function of data features.

struct MLSupportVectorClassifier

A classifier that predicts a binary target value by maximizing the separation between categories.

See Also

Tabular Data

Creating a Model from Tabular Data

Train a machine learning model by using Core ML to import and manage tabular data.

enum MLRegressor

A model you train to estimate continuous values.

struct MLRecommender

A model you train to make recommendations based on item similarity, grouping, and, optionally, item ratings.

struct MLDataTable

A table of data for training or evaluating a machine learning model.

enum MLDataValue

The value of a cell in a data table.