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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bilel El Yaagoubi
CaCaoCritics
Commits
c715efef
Commit
c715efef
authored
3 years ago
by
Tom Bray
Browse files
Options
Downloads
Patches
Plain Diff
algo final
parent
c3631a87
No related branches found
No related tags found
1 merge request
!19
Search algo
Pipeline
#42630
passed
3 years ago
Stage: lint
Stage: build
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
algo/adreco.py
+15
-9
15 additions, 9 deletions
algo/adreco.py
with
15 additions
and
9 deletions
algo/adreco.py
+
15
−
9
View file @
c715efef
...
@@ -101,7 +101,6 @@ def index_from_id(df,id):
...
@@ -101,7 +101,6 @@ def index_from_id(df,id):
'''
'''
return the index of a movie from its id
return the index of a movie from its id
'''
'''
print
(
df
[
df
[
'
original_title
'
]
==
'
Uncharted
'
].
index
.
values
[
0
])
return
df
[
df
[
'
_id
'
]
==
id
].
index
.
values
[
0
]
return
df
[
df
[
'
_id
'
]
==
id
].
index
.
values
[
0
]
...
@@ -167,30 +166,39 @@ def userDbToDf():
...
@@ -167,30 +166,39 @@ def userDbToDf():
return
df
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
and ponderating the vectMatrix of all film liked
"""
#fetch movies ID and index from the liked_movies
moviesID
=
usersdf
[
'
liked_movies
'
].
iloc
[
user_index
]
moviesID
=
usersdf
[
'
liked_movies
'
].
iloc
[
user_index
]
print
(
moviesID
)
print
(
'
Hello
'
)
moviesindex
=
[
index_from_id
(
moviesdf
,
ID
)
for
ID
in
moviesID
]
moviesindex
=
[
index_from_id
(
moviesdf
,
ID
)
for
ID
in
moviesID
]
n
=
len
(
moviesID
)
#number of film liked
n
=
len
(
moviesID
)
#number of film liked
if
moviesindex
!=
[]:
if
moviesindex
!=
[]:
#creates the vector of the user
vectuser
=
vectMatrix
[
moviesindex
[
0
]]
vectuser
=
vectMatrix
[
moviesindex
[
0
]]
moviesindex
.
pop
(
0
)
moviesindex
.
pop
(
0
)
for
i
in
moviesindex
:
for
i
in
moviesindex
:
vectuser
=
vectuser
+
vectMatrix
[
i
]
vectuser
=
vectuser
+
vectMatrix
[
i
]
vectuser
=
vectuser
/
n
vectuser
=
vectuser
/
n
#calculates the user similarity
calculated_sim
=
cosine_similarity
(
vectuser
,
vectMatrix
)
calculated_sim
=
cosine_similarity
(
vectuser
,
vectMatrix
)
similarity_scores
=
list
(
enumerate
(
calculated_sim
[
0
]))
similarity_scores
=
list
(
enumerate
(
calculated_sim
[
0
]))
similarity_scores_sorted
=
sorted
(
similarity_scores
,
key
=
lambda
x
:
x
[
1
],
reverse
=
True
)
similarity_scores_sorted
=
sorted
(
similarity_scores
,
key
=
lambda
x
:
x
[
1
],
reverse
=
True
)
#lists recommendations index of the movies, ordered by weights
recommendations_indices
=
[
t
[
0
]
for
t
in
similarity_scores_sorted
[
1
:(
100
+
1
)]]
recommendations_indices
=
[
t
[
0
]
for
t
in
similarity_scores_sorted
[
1
:(
100
+
1
)]]
return
recommendations_indices
return
recommendations_indices
else
:
else
:
return
return
[
i
for
i
in
range
(
100
)]
def
loadRecDB
():
def
loadRecDB
():
...
@@ -223,10 +231,8 @@ def updateDB():
...
@@ -223,10 +231,8 @@ def updateDB():
rec_indices
=
user_profile
(
i
,
moviesdf
,
usersdf
,
vect_matrix
)
rec_indices
=
user_profile
(
i
,
moviesdf
,
usersdf
,
vect_matrix
)
if
rec_indices
!=
None
:
if
rec_indices
!=
None
:
print
(
'
pass
'
)
recdf
=
moviesdf
[
'
id
'
].
iloc
[
rec_indices
]
recdf
=
moviesdf
[
'
id
'
].
iloc
[
rec_indices
]
titledf
=
moviesdf
[
'
original_title
'
].
iloc
[
rec_indices
]
print
(
recdf
)
for
j
in
recdf
.
index
:
for
j
in
recdf
.
index
:
recommended_movies
.
append
(
int
(
recdf
[
j
]))
recommended_movies
.
append
(
int
(
recdf
[
j
]))
...
...
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