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, 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, featureColumns: [String]?)

Creates a classifier from the feature columns in the training data to predict the 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.

Inspecting a Model

var model: MLModel

The underlying Core ML model stored in memory.

Describing a Model

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 similarities, and optionally, user ratings.

Beta
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.