<!--
{
  "availability" : [
    "macOS: 10.15.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateML",
  "identifier" : "/documentation/CreateML/MLRecommender",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Create ML"
    ],
    "preciseIdentifier" : "s:8CreateML13MLRecommenderV"
  },
  "title" : "MLRecommender"
}
-->

# MLRecommender

A model you train to make recommendations based on item similarity,
grouping, and, optionally, item ratings.

```
struct MLRecommender
```

## Overview

Use an [`MLRecommender`](/documentation/CreateML/MLRecommender) to train a machine learning model that you include
in your app to make recommendations for the user, while keeping their data
on-device.

You create a recommender model by training it with tabular data that
includes columns for the recommendation items and the groups the items
belong to. You also have the option to include an item rating column, which
gives higher-rated items more weight than those with lesser or negative
ratings. The recommender uses the training information to find similarity
patterns by looking at items that occur in groups or have similar ratings
within groups.

After you train a recommender, you save it as a Core ML model file with the
`.mlmodel` extension. Import this model file into your Xcode project by
dragging it into the Project navigator. At runtime, use the recommender to
make item suggestions to the user based on the patterns in training data and
the user’s item history. For example, a hiking app can recommend trails
based on the trails a user has previously hiked and their ratings of those
trails.

## Topics

### Creating and training a recommender

[`init(trainingData:userColumn:itemColumn:ratingColumn:parameters:)`](/documentation/CreateML/MLRecommender/init(trainingData:userColumn:itemColumn:ratingColumn:parameters:))

Creates an instance given a table and the names of the item and user columns contained therein.

[`MLRecommender.ModelParameters`](/documentation/CreateML/MLRecommender/ModelParameters-swift.struct)

Parameters that affect the process of training a recommender model.

[`modelParameters`](/documentation/CreateML/MLRecommender/modelParameters-swift.property)

The configuration parameters that the recommender used for training during initialization.

[`userIdentifierColumn`](/documentation/CreateML/MLRecommender/userIdentifierColumn)

The name of the column you selected at initialization to define the user identifiers.

[`itemIdentifierColumn`](/documentation/CreateML/MLRecommender/itemIdentifierColumn)

The name of the column you selected at initialization to define the item identifiers.

[`ratingColumn`](/documentation/CreateML/MLRecommender/ratingColumn)

The name of the column you selected at initialization to define the ratings.

### Evaluating a recommender

[`evaluation(on:userColumn:itemColumn:ratingColumn:cutoffs:excludingObserved:)`](/documentation/CreateML/MLRecommender/evaluation(on:userColumn:itemColumn:ratingColumn:cutoffs:excludingObserved:))

Computes the metrics for the given testing data.

[`MLRecommenderMetrics`](/documentation/CreateML/MLRecommenderMetrics)

Metrics you use to evaluate a recommender’s performance.

### Testing a recommender

[`recommendations(fromUsers:maxCount:restrictingToItems:excluding:excludingObserved:)`](/documentation/CreateML/MLRecommender/recommendations(fromUsers:maxCount:restrictingToItems:excluding:excludingObserved:))

Retrieves the highest scored item for the given array of users, based on item similarity and the rating column.

[`MLIdentifier`](/documentation/CreateML/MLIdentifier)

A type the Create ML framework can use as a machine learning identifier.

[`getSimilarItems(fromItems:maxCount:)`](/documentation/CreateML/MLRecommender/getSimilarItems(fromItems:maxCount:))

Returns the top ranked similar items based on the model’s similarity
type.

### Saving a recommender

[`write(to:metadata:)`](/documentation/CreateML/MLRecommender/write(to:metadata:))

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

[`write(toFile:metadata:)`](/documentation/CreateML/MLRecommender/write(toFile:metadata:))

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

### Describing a recommender

[`model`](/documentation/CreateML/MLRecommender/model)

The Core ML model.

### Supporting types

[`MLRecommender.ModelAlgorithmType`](/documentation/CreateML/MLRecommender/ModelAlgorithmType)

The algorithms a recommender can use to make recommendations.

[`MLRecommender.SimilarityType`](/documentation/CreateML/MLRecommender/SimilarityType)

The metric by which the recommender computes item similarity.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)