Create recommendations based on explicit feedback with a matrix factorization modelStay organized with collectionsSave and categorize content based on your preferences.
This tutorial teaches you how to create amatrix factorization modeland train it on the customer movie ratings in themovielens1mdataset. You then
use the matrix factorization model to generate movie recommendations for users.
Using customer-provided ratings to train the model is called
training withexplicit feedback. Matrix factorization models are trained
using theAlternating Least Squares algorithmwhen you use
explicit feedback as training data.
Objectives
This tutorial guides you through completing the following tasks:
Creating a matrix factorization model by using theCREATE MODELstatement.
Sign in to your Google Cloud account. If you're new to
Google Cloud,create an accountto evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Roles required to select or create a project
Select a project: Selecting a project doesn't require a specific
IAM role—you can select any project that you've been
granted a role on.
Create a project: To create a project, you need the Project Creator role
(roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission.Learn how to grant
roles.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Roles required to select or create a project
Select a project: Selecting a project doesn't require a specific
IAM role—you can select any project that you've been
granted a role on.
Create a project: To create a project, you need the Project Creator role
(roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission.Learn how to grant
roles.
BigQuery is automatically enabled in new projects.
To activate BigQuery in a pre-existing project, go to
Enable the BigQuery API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM
role (roles/serviceusage.serviceUsageAdmin), which
contains theserviceusage.services.enablepermission.Learn how to grant
roles.
Create a matrix factorization model and train it on the data in theratingstable. The model is trained to predict a rating for every user-item pair,
based on the customer-provided movie ratings.
Optionally, you can view the model's training statistics in the
Google Cloud console.
A machine learning algorithm builds a model by creating many iterations of
the model using different parameters, and then selecting the version of the
model that minimizesloss.
This process is called empirical risk minimization. The model's training
statistics let you see the loss associated with each iteration of the model.
Follow these steps to view the model's training statistics:
In the Google Cloud console, go to theBigQuerypage.
TheTraining Data Losscolumn represents the loss metric calculated
after the model is trained. Because this is a matrix factorization model,
this column shows themean squared error.
Evaluate the performance of the model by comparing the predicted movie ratings
returned by the model against the actual user movie ratings from the training
data.
To avoid incurring charges to your Google Cloud account for the resources used in this
tutorial, either delete the project that contains the resources, or keep the project and
delete the individual resources.
You can delete the project you created.
Or you can keep the project and delete the dataset.
Delete your dataset
Deleting your project removes all datasets and all tables in the project. If you
prefer to reuse the project, you can delete the dataset you created in this
tutorial:
If necessary, open the BigQuery page in the Google Cloud console.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-05-08 UTC."],[],[]]