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.
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.
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。
- In the top navigation bar, hover over Products > artificial intelligence, and then click machine learning platform Pai.
- On the home page of machine learning Pai console, click open now.
- 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.
- 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.
- After successful opening, click to go to Pai Management Console.
Create Pai studio project
1. On the left navigation bar of the console, click studio.
- On the PAI studio page, click create project.
- 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.
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.
c. After carefully reading the big data computing service maxcompute service agreement, check that I have read and agreed, and finally click open now.
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.
- 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.
1. Click the home page in the left navigation bar.
- Find ALS implementation music recommendation in the template list, and then click create from template.
- In the new experiment box, click OK.
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.
The data displayed are as follows.
The data source contains four fields, including:
User: user ID.
Item: Music ID.
Score: the user’s score of the item.
- 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.
- Click the parameter settings on the right to see the default algorithm parameters in the template.
1 click Run in the upper left corner.
- Please wait patiently for 3-5 minutes, and the experimental run is completed as shown below.
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.
2. 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.
For example, to predict the score of user1 on music 978130429, just multiply the two vectors below.
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.