Learn R Programming

SAR (version 1.0.3)

rec_model: Azure product recommendations model class

Description

Class representing an individual product recommendations (SAR) model.

Arguments

Format

An R6 object of class rec_model.

Methods

  • new(...): Initialize a model object. See 'Initialization' for more details.

  • delete(confirm=TRUE): Delete the model.

  • user_predict(userdata, k=10): Get personalised recommendations from the model. See 'Recommendations' for more details.

  • item_predict(item, k=10): Get item-to-item recommendations from the model. See 'Recommendations' for more details.

  • get_model_url(): Get the individual service URL for this model.

Initialization

Generally, the easiest way to initialize a new model object is via the get_model() and train_model() methods of the rec_endpoint class, which will handle all the gory details.

Recommendations

These arguments are used for obtaining personalised and item-to-item recommendations.

  • userdata: The input data on users for which to obtain personalised recommendations. This can be:

    1. A character vector of user IDs. In this case, personalised recommendations will be computed based on the transactions in the training data, ignoring any transaction event IDs or weights.

    2. A data frame containing transaction item IDs, event types and/or weights, plus timestamps. In this case, all the transactions are assumed to be for a single (new) user. If the event types/weights are absent, all transactions are assigned equal weight.

    3. A data frame containing user IDs and transaction details as in (2). In this case, the recommendations are based on both the training data for the given user(s), plus the new transaction details.

  • item: A vector of item IDs for which to obtain item-to-item recommendations.

  • k: The number of recommendations to return. Defaults to 10.

Both the user_predict() and item_predict() methods return a data frame with the top-K recommendations and scores.

See Also

az_rec_service for the service backend, rec_endpoint for the client endpoint

API reference and SAR model description at the Product Recommendations API repo on GitHub

Examples

Run this code
# NOT RUN {
# get a recommender endpoint and previously-trained model
rec_endp <- rec_endpoint$new("myrecusacvjwpk4raost", admin_key="key1", rec_key="key2")
rec_model <- rec_endp$get_model("model1")

data(ms_usage)

# item recommendations for a set of user IDs
users <- unique(ms_usage$user)[1:5]
rec_model$user_predict(users)

# item recommendations for a set of user IDs and transactions (assumed to be new)
user_df <- subset(ms_usage, user %in% users)
rec_model$user_predict(user_df)

# item recomendations for a set of item IDs
items <- unique(ms_usage$item)[1:5]
rec_model$item_predict(items)

# }

Run the code above in your browser using DataLab