In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "what is the principle of python matrix decomposition". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Principle: Matrix decomposition
Matrix decomposition is an algorithm in the recommendation system series, which, as the name implies, decomposes the matrix into two (or more) matrices, which are multiplied to get the original matrix. In the recommendation system, we usually start with the interaction / score matrix between the user and the project, and the matrix decomposition algorithm decomposes the user and project feature matrix, which is also known as embedding. Here is an example of the rating, purchase and other matrices in the movie recommendation.
Typically, in a dataset, you mine the potential characteristics of user and project properties. In essence, the underlying feature is the representation of the user / project in any space, indicating how the user evaluates the movie. In the example of the movie recommendation system, a user sample contains multiple movies he watches, and the higher the value of the latent feature, the more he likes that type of movie, so this type of movie should be recommended.
Prepare for
The data used in this article is from kaggle and contains 76000 user samples.
First, import the data and related libraries.
From recsys import *
From generic_preprocessing import
From IPython.display import HTML # # display in Ipython Notebook
Import pandas as pd,numpy as np
Anime = pd.read_csv ('anime.csv')
Ratings = pd.read_csv ('rating.csv'). Iloc [: 5000000]
In order to create a recommendation system, we need an interactive matrix. To do this, use the create_interaction_matrix function in the recsys module, which requires data of type DataFrame of Pandas as input, with columns such as user id, project id and score. Setting norm=True in this function means that the value of any score should be positive. In this example, there is no need to set it up because the actual purchase data and ratings are positive.
# create a matrix using rating data
Interactions = create_interaction_matrix (df = ratings
User_col = 'user_id'
Item_col = 'anime_id'
Rating_col = 'rating')
Interactions.shape
Then use the create_user_dict and create_item_dict functions (recsys module) to create dictionaries about users and projects.
# user Dictionary
User_dict = create_user_dict (interactions=interactions)
# Project Dictionary
Movies_dict = create_item_dict (df = anime
Id_col = 'anime_id'
Name_col = 'name') matrix decomposition model
Use the runMF function in recsys to create a matrix decomposition model, the parameters of this function:
Interaction: the matrix n_components created earlier: for the number of embeds per user and project loss: define a loss function, in this case we use the warp loss function because we are more concerned about the rank of the matrix. Epoch: number of runs n_jobs: number of cores used in parallel processing mf_model = runMF (interactions = interactions
N_components = 30
Loss = 'warp'
Epoch = 30
N_jobs = 4) this is the end of the introduction of "what is the principle of python matrix factorization". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.