0% found this document useful (0 votes)
0 views2 pages

Ex 3

The document outlines a project aimed at implementing user profile learning using Python, focusing on movie recommendations. It describes the user profiling process, which involves extracting and integrating keyword-based information to create structured profiles that personalize recommendations. The algorithm includes steps for loading datasets, creating item profiles, and predicting ratings based on user preferences, culminating in a successful execution of the program.

Uploaded by

gcollege700
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views2 pages

Ex 3

The document outlines a project aimed at implementing user profile learning using Python, focusing on movie recommendations. It describes the user profiling process, which involves extracting and integrating keyword-based information to create structured profiles that personalize recommendations. The algorithm includes steps for loading datasets, creating item profiles, and predicting ratings based on user preferences, culminating in a successful execution of the program.

Uploaded by

gcollege700
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Ex. No.

: 03
Implement User Profile Learning

Aim:
To implement user profile learning using Python

Description:

User Profiling:
User Profiling is the process of Extracting, Integrating and Identifying the keyword based information
to generate a structured Profile and then visualizing the knowledge out of these findings. User
profiling helps personalizing a system to work according to user. Therefore user profiling or
personalization is one of the major concepts used for accessing the user relevant information, which
can be used to solve the difficult problems of recommender system like classification and ranking of
items in accordance with an individual's interest.
Algorithm:

Step 1: Include necessary packages.


Step 2: Load the dataset for movie recommendation
Step 3: Represent the movie based on genre using one hot encoding.
Step 4: From the user’s watch history, create a normalized vector represented by the genres.
Step 5: For every new movie, multiply the user profile created with the item profile of that movie.
Step 6: The sum of the weights gives the rating of the new movies and the movies with high
predicted ratings are recommended to the user.

Code:
#creating Item Profile for watched movies
import pandas as pd
import numpy as np

#function to create movie profile


def item_profile(mname):
movies1=pd.read_csv(mname)
mov_index1=movies1.loc[:,"movie"]
movies1.index=mov_index1.tolist()
movies1=movies1.loc[:, movies1.columns.drop(['movie'])]
g_p1=movies1.genre.str.split('|').explode().value_counts()
g_p1=g_p1.keys().tolist()
g_p1.sort()
l_df1=len(movies1)
list21=[]
for i in range(l_df1):
list21.append(0)
for i in g_p1:
movies1[i]=list21
for index,row in movies1.iterrows():
gg1=row.genre.split('|')
for j in gg1:
movies1.at[index,j]=1
m11=movies1.loc[:, movies1.columns.drop(['genre'])]
return(m11)

#create item profile for watched movies


m1 = pd.DataFrame()
m1= item_profile('movies.csv')
print(m1)

#create item profile for watched movies


m11 = pd.DataFrame()
m11= item_profile('movies_new.csv')
print(m11)

#create matrix for user-item interaction


dataset = pd.read_csv('ratings.csv', header=0, names=['userid', 'movie', 'rating',])
d1 = dataset.pivot_table(index='movie',columns='userid',values='rating')
d1=d1.fillna(0)
d1=d1.sort_index(axis = 0)
print("\ncreated utility matrix")
print(d1)

#creating user profile


inp=input("Enter the user_ID for creating user profile")
d2=d1.loc[:,inp]
wm1=m1.mul(d2,axis=0)
mm1=wm1.sum()
tot=mm1.sum()
mm1=mm1/tot
mm1=mm1.sort_values(ascending=False)
print("Created user profile:\n",mm2)
up1=mm1.keys().tolist()
print("\nUser ",inp, " prefers to watch movies in ",up1[0]," , ",up1[1], " genre highly")

#rating prediction
wm2=m11.mul(mm1,axis=1)
wm2=wm2.sum(axis=1)
print("\nThe possible rating that ", inp, "give to new movies are:\n")
print(round(wm2*10),0)

Result:
Thus the Python program to implement user profile learning was executed successfully.

You might also like