The ML.RECOMMEND function

This document describes the ML.RECOMMEND function, which lets you generate a predicted rating for every user-item row combination for a matrix factorization model. Because the input data for a matrix factorization model tends to be a sparse matrix with missing values, ML.RECOMMEND can return the predictions for those missing values without requiring specification of each entry.

Syntax

ML.RECOMMEND(
  MODEL `project_id.dataset.model`
  [, { TABLE `project_id.dataset.table` | (query_statement) }]
  [, STRUCT(trial_id AS trial_id)])

Arguments

ML.RECOMMEND takes the following arguments:

Output

ML.RECOMMEND outputs at least 3 columns for all cases; the user column, the item column and a column for predicted recommendations.

The output of ML.RECOMMEND is computed as follows:

If the model was trained with feedback_type=EXPLICIT, a user column called user, and an item column called item, then ML.RECOMMEND returns the following columns:

If the model was trained with feedback_type=IMPLICIT, a user column called user, and an item column called item, then ML.RECOMMEND returns the following columns:

Examples

No input data

The following example generates predicted ratings for every user-item pair in the inputs of mymodel because there is no input data specified.

SELECT
  *
FROM
  ML.RECOMMEND(MODEL `mydataset.mymodel`)

With input data

The following example generates predicted ratings for each user-item row in mydataset.mytable assuming that mydataset.mymodel was trained using the user column user and item column item.

SELECT
  *
FROM
  ML.RECOMMEND(MODEL `mydataset.mymodel`,
      (
      SELECT
        user,
        item
      FROM
        `mydataset.mytable`))

What's next