Structure

MLActivityClassifier

A model you train to classify activities based on motion sensor data.

Declaration

struct MLActivityClassifier

Overview

Use an MLActivityClassifier to train a machine learning model that you can include in your app to classify user movements.

When you create an activity classification model, you train it with tabular data you collect from motions sensors, such as a device’s accelerometer and gyroscope. For example, you can gather sensor data from an Apple Watch to classify a person waving, shaking hands, or throwing a ball.

After you train an activity classifier, you save it as a Core ML model file with the .mlmodel extension. You can then import this model file into an app that uses an activity classification model to recognize a person’s activity, based on their movements.

Topics

Creating and Training an Activity Classifier

enum MLActivityClassifier.DataSource

A data source for an activity classifier.

struct MLActivityClassifier.ModelParameters

Parameters that affect the process of training an activity classification model.

let modelParameters: MLActivityClassifier.ModelParameters

The configuration parameters that the activity classifier used for training during initialization.

Assessing Model Accuracy

var trainingMetrics: MLClassifierMetrics

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

var validationMetrics: MLClassifierMetrics

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

Evaluating an Activity Classifier

func evaluation(on: MLActivityClassifier.DataSource, featureColumns: [String], labelColumn: String?, recordingFileColumn: String?) -> MLClassifierMetrics

Generates metrics describing the activity classifier’s performance on labelled activities in a data source.

func evaluation(on: MLDataTable, featureColumns: [String], labelColumn: String, recordingFileColumn: String) -> MLClassifierMetrics

Generates metrics describing the activity classifier’s performance on labelled activities in a data table.

Testing an Activity Classifier

func predictions(from: MLDataTable, perWindowPrediction: Bool?) -> [String]

Classifies the given activities from the provided data table.

Saving an Activity Classifier

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

Exports the activity classifier as a Core ML model file at the given URL.

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

Exports the activity classifier as a Core ML model file at the given file path.

Describing an Activity Classifier

var recordingFileColumn: String

The name of the column containing the recording file names.

var labelColumn: String

The name of the column containing the activity labels.

var featureColumns: [String]

The names of the columns the activity classifier uses when classifiying an activity.

var model: MLModel

The underlying Core ML model of the activity classifier stored in memory.

var description: String

A text representation of the activity classifier.

var debugDescription: String

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

var playgroundDescription: Any

A description of the activity classifier shown in a playground.

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