Enumeration

MLRegressor

A model you train to estimate continuous values.

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.

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.

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

Categorization and Quantity Estimation

enum MLClassifier

A model you train to classify data into discrete categories.

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