Protocol

MLFeatureProvider

An interface that represents a collection of values for either a model's input or its output.

Declaration

@protocol MLFeatureProvider

Overview

Use MLFeatureProvider to customize the way your app gets data to and from your model when the model's dynamically generated interface doesn't meet your app's needs.

Consider adopting this protocol in your data source if any of the following apply:

  • Your data is collected asynchronously.

  • Using the autogenerated interface leads to copying excessive amounts of data.

  • Your data source is otherwise complicated.

The interface is mainly an accessor for MLFeatureValue instances, making it straightforward to implement. Adopting this protocol allows you to integrate your data directly with MLModel, which means the model can query your data sources without constructing a separate input instance.

To customize your app's interaction with a model:

  1. Adopt the MLFeatureProvider protocol in a class or structure so that the model can query it for input feature values via featureValueForName:.

  2. Pass your app's MLFeatureProvider to your MLModel with predictionFromFeatures:error: or predictionFromFeatures:options:error:.

  3. Use the MLFeatureProvider returned from a prediction(from:) method to get the output feature values for that prediction.

Topics

Accessing Values

- featureValueForName:

Accesses the feature value given the feature's name.

Required.

featureNames

The set of valid feature names.

Required.

Relationships

See Also

Model Features

MLFeatureValue

A feature's value and its type bundled as a read-only instance.

MLDictionaryFeatureProvider

A convenience wrapper for the given dictionary of data.

MLBatchProvider

An interface that represents a collection of feature providers.

MLArrayBatchProvider

A convenience wrapper for batches of feature providers.