turicreate.recommender.create¶
-
turicreate.recommender.
create
(observation_data, user_id='user_id', item_id='item_id', target=None, user_data=None, item_data=None, ranking=True, verbose=True)¶ A unified interface for training recommender models. Based on simple characteristics of the data, a type of model is selected and trained. The trained model can be used to predict ratings and make recommendations.
To use specific options of a desired model, use the
create
function of the corresponding model.Parameters: - observation_data : SFrame
The dataset to use for training the model. It must contain a column of user ids and a column of item ids. Each row represents an observed interaction between the user and the item. The (user, item) pairs are stored with the model so that they can later be excluded from recommendations if desired. It can optionally contain a target ratings column. All other columns are interpreted by the underlying model as side features for the observations.
The user id and item id columns must be of type ‘int’ or ‘str’. The target column must be of type ‘int’ or ‘float’.
- user_id : string, optional
The name of the column in observation_data that corresponds to the user id.
- item_id : string, optional
The name of the column in observation_data that corresponds to the item id.
- target : string, optional
Name of the column in observation_data containing ratings given by users to items, if applicable.
- user_data : SFrame, optional
Side information for the users. This SFrame must have a column with the same name as what is specified by the user_id input parameter. user_data can provide any amount of additional user-specific information.
- item_data : SFrame, optional
Side information for the items. This SFrame must have a column with the same name as what is specified by the item_id input parameter. item_data can provide any amount of additional item-specific information.
- ranking : bool, optional
Determine whether or not the goal is to rank items for each user.
- verbose : bool, optional
Enables verbose output.
Returns: - out : A trained model.
- If a target column is given, then
turicreate.recommender.factorization_recommender.FactorizationRecommender
. - If no target column is given, then
turicreate.recommender.item_similarity_recommender.ItemSimilarityRecommender
.
- If a target column is given, then
Examples
Basic usage
Given basic user-item observation data, an
ItemSimilarityRecommender
is created:>>> sf = turicreate.SFrame({'user_id': ['0', '0', '0', '1', '1', '2', '2', '2'], ... 'item_id': ['a', 'b', 'c', 'a', 'b', 'b', 'c', 'd']}) >>> m = turicreate.recommender.create(sf) >>> recs = m.recommend()
Creating a model for ratings data
This trains a
FactorizationRecommender
that can predict target ratings:>>> sf2 = turicreate.SFrame({'user_id': ['0', '0', '0', '1', '1', '2', '2', '2'], ... 'item_id': ['a', 'b', 'c', 'a', 'b', 'b', 'c', 'd'], ... 'rating': [1, 3, 2, 5, 4, 1, 4, 3]}) >>> m2 = turicreate.recommender.create(sf2, target="rating", ranking = False)
Creating specific models
Specific models allow for a number of additional options during create. The available recommenders are all in the turicreate.recommender namespace. For the complete list of acceptable options, please refer to the documentation for individual models. Such options can be passed to the underlying model just like any other parameter. For example, the following code creates an
ItemSimilarityRecommender
with a space-saving option called only_top_k. The returned model stores only the 2 most similar items for item:>>> from turicreate.recommender import item_similarity_recommender >>> item_similarity_recommender.create(sf, only_top_k=2)