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
539ae24b
Commit
539ae24b
authored
3 years ago
by
Tom Bray
Browse files
Options
Downloads
Patches
Plain Diff
primary recommendation system done
parent
e1602073
No related branches found
No related tags found
1 merge request
!12
Search algo
Pipeline
#42525
passed
3 years ago
Stage: lint
Stage: build
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
algo/recommendation.py
+5
-7
5 additions, 7 deletions
algo/recommendation.py
with
5 additions
and
7 deletions
algo/recommendation.py
+
5
−
7
View file @
539ae24b
from
pymongo
import
MongoClient
import
pandas
as
pd
#
import ast
import
ast
from
sklearn.feature_extraction.text
import
CountVectorizer
from
sklearn.feature_extraction.text
import
TfidfVectorizer
from
sklearn.metrics.pairwise
import
cosine_similarity
#
import seaborn as sns
import
seaborn
as
sns
import
numpy
as
np
import
matplotlib.pyplot
as
plt
...
...
@@ -16,9 +16,8 @@ def dbToDf():
client
=
MongoClient
(
"
mongodb://group3:GJF6cQqM4RLxBfNb@cs2022.lmichelin.fr:27017/group3?ssl=true
"
)
db
=
client
.
group3
collection
=
db
.
movies_populated
cursor
=
collection
.
find
()
cursor
=
collection
.
find
(
{},{
"
_id
"
:
1
,
"
original_title
"
:
1
,
"
genre
"
:
1
,
"
id
"
:
1
,
"
overview
"
:
1
,
"
popularity
"
:
1
,
"
vote_count
"
:
1
,
"
release_date
"
:
1
,
"
cast
"
:
{
"
name
"
:
1
,
"
order
"
:
1
}}
)
df
=
pd
.
DataFrame
(
list
(
cursor
))
return
df
def
preFiltering
(
df
,
percent
=
15
):
...
...
@@ -49,7 +48,7 @@ def similarity(df):
'''
tf_idf
=
TfidfVectorizer
(
stop_words
=
'
english
'
)
tf_idf_matrix
=
tf_idf
.
fit_transform
(
df
[
'
overview
'
]);
print
(
tf_idf_matrix
)
# calculating cosine similarity between movies
cosine_similarity_matrix
=
cosine_similarity
(
tf_idf_matrix
,
tf_idf_matrix
)
...
...
@@ -83,7 +82,6 @@ def recommendations_on_overview( original_title, df, number_of_recommendations):
#calculates similarity scores of all movies
calculated_sim
=
similarity
(
df
)
similarity_scores
=
list
(
enumerate
(
calculated_sim
[
index
]))
similarity_scores_sorted
=
sorted
(
similarity_scores
,
key
=
lambda
x
:
x
[
1
],
reverse
=
True
)
...
...
@@ -94,4 +92,4 @@ def recommendations_on_overview( original_title, df, number_of_recommendations):
df
=
dbToDf
()
print
(
recommendations_on_overview
(
'
Batman
'
,
df
,
9
))
\ No newline at end of file
print
(
recommendations_on_overview
(
'
Avatar
'
,
df
,
9
))
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