Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CaCaoCritics
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bilel El Yaagoubi
CaCaoCritics
Commits
79ee928d
Commit
79ee928d
authored
2 years ago
by
Tom Bray
Browse files
Options
Downloads
Patches
Plain Diff
clean code adreco
parent
36465458
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
algo/adreco.py
+31
-24
31 additions, 24 deletions
algo/adreco.py
with
31 additions
and
24 deletions
algo/adreco.py
+
31
−
24
View file @
79ee928d
...
@@ -36,6 +36,29 @@ def movieDbToDf():
...
@@ -36,6 +36,29 @@ def movieDbToDf():
return
df
return
df
def
userDbToDf
():
'''
This function convert a movie DataBase from mongoDB into a pandas DataFrame
'''
#load DB
client
=
MongoClient
(
"
mongodb://group3:GJF6cQqM4RLxBfNb@cs2022.lmichelin.fr:27017/group3?ssl=true
"
)
db
=
client
.
group3
collection
=
db
.
users
#projection on useful data
cursor
=
collection
.
find
({},{
"
_id
"
:
1
,
"
liked_movies
"
:
1
,
"
update
"
:
1
})
df
=
pd
.
DataFrame
(
list
(
cursor
))
return
df
def
loadRecDB
():
#load DB
client
=
MongoClient
(
"
mongodb://group3:GJF6cQqM4RLxBfNb@cs2022.lmichelin.fr:27017/group3?ssl=true
"
)
db
=
client
.
group3
collection
=
db
[
'
recommendations
'
]
return
collection
def
preFiltering
(
df
,
percent
=
90
):
def
preFiltering
(
df
,
percent
=
90
):
'''
'''
This function removes movies who do not have enough votes to be evaluated
This function removes movies who do not have enough votes to be evaluated
...
@@ -103,7 +126,6 @@ def index_from_id(df,id):
...
@@ -103,7 +126,6 @@ def index_from_id(df,id):
'''
'''
return
df
[
df
[
'
_id
'
]
==
id
].
index
.
values
[
0
]
return
df
[
df
[
'
_id
'
]
==
id
].
index
.
values
[
0
]
def
recommendations
(
original_title
,
df
,
number_of_recommendations
):
def
recommendations
(
original_title
,
df
,
number_of_recommendations
):
#prefilter the dataframe
#prefilter the dataframe
...
@@ -130,6 +152,10 @@ def recommendations(original_title, df, number_of_recommendations):
...
@@ -130,6 +152,10 @@ def recommendations(original_title, df, number_of_recommendations):
return
df
[
'
original_title
'
].
iloc
[
recommendations_indices
]
return
df
[
'
original_title
'
].
iloc
[
recommendations_indices
]
def
formatingFeatures
(
df_row
):
def
formatingFeatures
(
df_row
):
"""
This function creates a new column
"
features
"
in the df
used to calculate similarities between users_profiles et movies
"""
g
=
[]
g
=
[]
genres
=
[]
genres
=
[]
k
=
[]
k
=
[]
...
@@ -150,21 +176,6 @@ def formatingFeatures(df_row):
...
@@ -150,21 +176,6 @@ def formatingFeatures(df_row):
return
'
'
.
join
([
genres
]
*
w_genres
)
+
'
'
+
'
'
.
join
([
keywords
]
*
w_keywords
)
+
'
'
+
'
'
.
join
([
str
(
df_row
[
'
main_actor
'
])]
*
w_actor
)
+
'
'
+
'
'
.
join
([
str
(
df_row
[
'
director
'
])]
*
w_director
)
+
'
'
+
'
'
.
join
([
str
(
df_row
[
'
release_date
'
])]
*
w_release_date
)
return
'
'
.
join
([
genres
]
*
w_genres
)
+
'
'
+
'
'
.
join
([
keywords
]
*
w_keywords
)
+
'
'
+
'
'
.
join
([
str
(
df_row
[
'
main_actor
'
])]
*
w_actor
)
+
'
'
+
'
'
.
join
([
str
(
df_row
[
'
director
'
])]
*
w_director
)
+
'
'
+
'
'
.
join
([
str
(
df_row
[
'
release_date
'
])]
*
w_release_date
)
def
userDbToDf
():
'''
This function convert a movie DataBase from mongoDB into a pandas DataFrame
'''
#load DB
client
=
MongoClient
(
"
mongodb://group3:GJF6cQqM4RLxBfNb@cs2022.lmichelin.fr:27017/group3?ssl=true
"
)
db
=
client
.
group3
collection
=
db
.
users
#projection on useful data
cursor
=
collection
.
find
({},{
"
_id
"
:
1
,
"
liked_movies
"
:
1
,
"
update
"
:
1
})
df
=
pd
.
DataFrame
(
list
(
cursor
))
return
df
def
user_profile
(
user_index
,
moviesdf
,
usersdf
,
vectMatrix
):
def
user_profile
(
user_index
,
moviesdf
,
usersdf
,
vectMatrix
):
"""
"""
This function creates a user profile based on the likef movies of the user
This function creates a user profile based on the likef movies of the user
...
@@ -200,15 +211,11 @@ def user_profile( user_index, moviesdf, usersdf, vectMatrix ):
...
@@ -200,15 +211,11 @@ def user_profile( user_index, moviesdf, usersdf, vectMatrix ):
else
:
else
:
return
[
i
for
i
in
range
(
100
)]
return
[
i
for
i
in
range
(
100
)]
def
loadRecDB
():
#load DB
client
=
MongoClient
(
"
mongodb://group3:GJF6cQqM4RLxBfNb@cs2022.lmichelin.fr:27017/group3?ssl=true
"
)
db
=
client
.
group3
collection
=
db
[
'
recommendations
'
]
return
collection
def
updateDB
():
def
updateDB
():
"""
This function update the recommandation DB based on the likes of thes users
"""
#loadDB
#loadDB
moviesdf
=
movieDbToDf
()
moviesdf
=
movieDbToDf
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment