Enumeration

MLRegressor

A model you train to estimate continuous values.

Declaration

enum MLRegressor

Overview

Use an MLRegressor to estimate continuous values like price, time, or temperature.

A regressor differs from a classifier because it can predict output values not seen during the training process. By contrast, a classifier can only classify input into the categories that it was trained on.

For example, when estimating housing prices on Mars, a regressor can interpolate between the examples to estimate prices not seen during training. The figure below shows a linear regressor for Mars real-estate prices similar to the Integrating a Core ML Model into Your App sample.

A graph showing housing prices for mars with a linear regressor used to create a continuous estimation between points.

In this case, no examples of 3 solar panels were provided, but the regressor can make an informed prediction about the housing price.

When you create an MLRegressor, your data is inspected and a specific regressor is chosen automatically (see Supporting Regressor Types).

Topics

Creating and Training a Model

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

Creates a regressor from the feature columns in the training data to predict the values in the target column.

Evaluating a Model

var trainingMetrics: MLRegressorMetrics

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

var validationMetrics: MLRegressorMetrics

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

func evaluation(on: MLDataTable) -> MLRegressorMetrics

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

Testing a Model with Unlabeled Data

var featureColumns: [String]

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

var targetColumn: String

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

func predictions(from: MLDataTable) -> MLUntypedColumn

Predicts the target value from the provided data.

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

var debugDescription: String

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

var playgroundDescription: Any

A description of the regressor shown in a playground.

Regressor Cases

The regressor case picked automatically when initializing an MLRegressor.

case linear(MLLinearRegressor)

A regressor that estimates the target as a linear function of the features.

case decisionTree(MLDecisionTreeRegressor)

A regressor that estimates the target by learning rules to split the data.

case boostedTree(MLBoostedTreeRegressor)

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

case randomForest(MLRandomForestRegressor)

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

Supporting Regressor Types

struct MLLinearRegressor

A regressor that estimates the target as a linear function of the features.

struct MLDecisionTreeRegressor

A regressor that estimates the target by learning rules to split the data.

struct MLRandomForestRegressor

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

struct MLBoostedTreeRegressor

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

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 MLClassifier

A model you train to classify data into discrete categories.

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.