Introduction to recommender system using ALS algorithm to achieve scoring prediction

Time:2021-4-12

brief introduction

The scene will be based on the machine learning Pai platform to guide you how to use ALS algorithm to achieve user music score prediction.

background information

ALS algorithm is a model-based recommendation algorithm. The basic idea is to decompose the sparse matrix and evaluate the value of missing items to get a basic training model. Then according to this model, we can evaluate the new user and item data. ALS uses the alternating least square method to calculate the missing items. The alternating least square method is developed on the basis of the least square method.

In terms of classification of collaborative filtering, ALS algorithm belongs to user item CF, also known as hybrid CF, which considers both user and item.

In this user music scoring scenario, the first raw data obtained is the score matrix A of each audience for each song. This score may be very sparse, because not every user has heard all songs, and not every user will score every song.
Introduction to recommender system using ALS algorithm to achieve scoring prediction
ALS matrix decomposition will decompose matrix A into the multiplication of two matrices, namely x matrix and Y matrix.

Matrix A = product of the rank of matrix X and Y

The column representation of X and the horizontal representation of y can be called the factor in ALS. This factor is implicitly defined. Here, it is assumed that there are three factors: personality, education level and hobby. The X and Y matrices of a matrix decomposed by ALS can be expressed as follows.

X matrix:
Introduction to recommender system using ALS algorithm to achieve scoring prediction
Y matrix:

Introduction to recommender system using ALS algorithm to achieve scoring prediction
After the data is disassembled in this way, it is easy for users to predict the score of music. For example, there is listener 6, who has never heard the song “red bean”, but we can get the vector m of X matrix in the matrix decomposition of listener 6. At this time, only by multiplying the vector m and the corresponding vector n of “red bean” in the Y matrix can we predict the score of listener 6 on the song “red bean”.

Opening machine learning Pai service

Note: the machine learning Pai service used in this scenario relies on maxcompute big data computing service, which will consume about 2.5 yuan of computing cost when running the experiment. Please ensure that your account balance is sufficient.

1. Log in with an alicloud accountAlibaba cloud official website
Introduction to recommender system using ALS algorithm to achieve scoring prediction

  1. In the top navigation bar, hover over Products > artificial intelligence, and then click machine learning platform Pai.

Introduction to recommender system using ALS algorithm to achieve scoring prediction

  1. On the home page of machine learning Pai console, click open now.

Introduction to recommender system using ALS algorithm to achieve scoring prediction

  1. On the service opening page, select the region of the machine learning Pai service to be opened, such as East China 2 (Shanghai), and then click buy now at the bottom of the page.

Introduction to recommender system using ALS algorithm to achieve scoring prediction

  1. On the order confirmation page, after carefully reading the “machine learning (PAI) service agreement”, check that I have read and agreed, and finally click open now.

Introduction to recommender system using ALS algorithm to achieve scoring prediction

  1. After successful opening, click to go to Pai Management Console.

Introduction to recommender system using ALS algorithm to achieve scoring prediction

Create Pai studio project

1. On the left navigation bar of the console, click studio.
Introduction to recommender system using ALS algorithm to achieve scoring prediction

  1. On the PAI studio page, click create project.

Introduction to recommender system using ALS algorithm to achieve scoring prediction

  1. In the create project page that pops up on the right, maxcompute selects pay as you go, fills in the project name, and then click OK.

The underlying computing of Pai studio relies on maxcompute. If you have not opened maxcompute in the current area, please follow the prompts on the page to buy it.

a. Click buy.

Introduction to recommender system using ALS algorithm to achieve scoring prediction

b. Select the region where the machine learning Pai service opened in step 1, such as East China 2 (Shanghai), and then click buy now.

Introduction to recommender system using ALS algorithm to achieve scoring prediction

c. After carefully reading the big data computing service maxcompute service agreement, check that I have read and agreed, and finally click open now.

Introduction to recommender system using ALS algorithm to achieve scoring prediction

d. After successful opening, return to the PAI studio console page, click create project again, select the maxcompute payment method as pay as you go on the create project page, fill in the project name, and finally click OK.

Introduction to recommender system using ALS algorithm to achieve scoring prediction

  1. It takes about 1 minute for the project to be initialized. Wait for the project operation column to appear and enter machine learning, indicating that the project creation is completed.

Introduction to recommender system using ALS algorithm to achieve scoring prediction

Create experiments

1. Click the home page in the left navigation bar.
Introduction to recommender system using ALS algorithm to achieve scoring prediction

  1. Find ALS implementation music recommendation in the template list, and then click create from template.

Introduction to recommender system using ALS algorithm to achieve scoring prediction

  1. In the new experiment box, click OK.

Introduction to recommender system using ALS algorithm to achieve scoring prediction

View experiment template

The data source of the experiment and the parameters of ALS matrix decomposition component have been configured by default in this template.

1. Right click the data source node, and then click view data.
Introduction to recommender system using ALS algorithm to achieve scoring prediction
The data displayed are as follows.
Introduction to recommender system using ALS algorithm to achieve scoring prediction
The data source contains four fields, including:

User: user ID.
Item: Music ID.
Score: the user’s score of the item.

  1. Click the ALS matrix factorization-1 node, and the following is displayed on the right side. You can see that the field settings have been set to be consistent with the fields in the data source.

Introduction to recommender system using ALS algorithm to achieve scoring prediction

  1. Click the parameter settings on the right to see the default algorithm parameters in the template.

Introduction to recommender system using ALS algorithm to achieve scoring prediction

Operation experiment

1 click Run in the upper left corner.
Introduction to recommender system using ALS algorithm to achieve scoring prediction

  1. Please wait patiently for 3-5 minutes, and the experimental run is completed as shown below.

Introduction to recommender system using ALS algorithm to achieve scoring prediction

View the experimental results

This experiment will output two tables, corresponding to the X matrix and Y matrix in ALS algorithm.

1. After the experiment is completed, right-click ALS matrix factorization-1 in the canvas, and select View Data > View output pile 1 in the shortcut menu to view matrix X.
Introduction to recommender system using ALS algorithm to achieve scoring prediction2. Right click ALS matrix factorization-1 in the canvas and select View Data > View output pile 2 in the shortcut menu to view matrix y.
Introduction to recommender system using ALS algorithm to achieve scoring prediction
Forecast score
For example, to predict the score of user1 on music 978130429, just multiply the two vectors below.

user1:[-0.14220297,0.8327106,0.5352268,0.6336995,1.2326205,0.7112976,0.9794858,0.8489773,0.330319,0.7426911]
item978130429:[0.2431642860174179,0.6019538044929504,0.4035401940345764,0.254305899143219,0.4056856632232666,0.46871861815452576,0.3701469600200653,0.3757922947406769,0.26486095786094666,0.37488409876823425]
After calculation, the result of the multiplication of the two vectors is 2.7247730805432644, which can predict that the score of user 1 to music 978130429 is 2.7247730805432644.