Enumeration

MLClassifier

A model you train to classify data into discrete categories.

Overview

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

For example, to predict whether a sports team will win or lose, you can give your model inputs such as the team's win-loss ratio and game location to classify the team's next game into the "Win" or "Lose" categories.

When you create an MLClassifier, your data is inspected and a specific classifier is chosen automatically (see Supporting Classifier Types).

Topics

Creating and Training a Model

init(trainingData: MLDataTable, targetColumn: String)

Creates a classifier from a table of training data that is trained to predict categories in the target column.

Evaluating a Model

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.

func evaluation(on: MLDataTable) -> MLClassifierMetrics

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

Testing a Model with Unlabeled Data

var featureColumns: [String]

The column names used by the classifer when accepting input data for classification.

var targetColumn: String

The name of the column you want the classifier to make predictions for.

func predictions(from: MLDataTable) -> MLUntypedColumn

Classifies the provided data into the target categories.

Saving a Model

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.

struct MLModelMetadata

Information about a model that’s stored in a Core ML model file.

Inspecting a Model

var model: MLModel

The underlying Core ML model stored in memory.

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

Categorization and Quantity Estimation

enum MLRegressor

A model you train to estimate continuous values.

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software