Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taskA
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
group18
taskA
Commits
dad3555b
Commit
dad3555b
authored
Aug 28, 2016
by
DIVYANSH PAREEK
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update collab-filter.py for final movie recommendation referring to task A.3
parent
3e4969bd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
4 deletions
+31
-4
collab-filter.py
collab-filter.py
+31
-4
No files found.
collab-filter.py
View file @
dad3555b
...
...
@@ -39,6 +39,7 @@ userFile.close()
#data is complete at this point
# Pearson Correlation Basic Implementation Using for Loop
pearson
=
[]
rows
=
len
(
data
)
users
=
data
[
rows
-
1
]
...
...
@@ -68,9 +69,35 @@ for x in range(1,rows-1): # does not include (rows-1)
summ
=
nume
/
deno
else
:
summ
=
1
pearson
.
append
((
summ
,
lis
[
0
])
)
data
[
x
]
.
append
(
summ
)
else
:
pearson
.
append
((
0
,
lis
[
0
]))
data
[
x
]
.
append
(
0
)
# explicit choice to take summ = 1 for the corner case ... However, we were told no such "Pathological Cases" would be given
# print(data)
# Humanity's Answer : Suggesting Movies
review
=
[]
for
i
in
range
(
1
,
cols
):
if
(
float
(
users
[
i
])
==
-
1
):
movie_name
=
data
[
0
][
i
]
movie_rate
=
0
sumcorrcoeff
=
0
for
g
in
range
(
1
,
rows
-
1
):
if
(
float
(
data
[
g
][
i
])
>=
0
):
movie_rate
+=
float
(
data
[
g
][
i
])
*
float
(
data
[
g
][
cols
])
sumcorrcoeff
+=
abs
(
float
(
data
[
g
][
cols
]))
if
(
sumcorrcoeff
>
0
):
movie_rate
=
movie_rate
/
sumcorrcoeff
else
:
# 0/0 format
movie_rate
=
0
review
.
append
((
movie_rate
,
movie_name
))
review
.
sort
(
reverse
=
True
)
number
=
len
(
review
)
number
=
min
(
3
,
number
)
print
(
"The top movie recommendations for this particular user are :"
)
for
x
in
range
(
number
):
print
(
review
[
x
][
1
])
pearson
.
sort
(
reverse
=
True
)
print
(
pearson
)
\ No newline at end of file
# Tried this, but didn't work, TypeError: map() takes 1 positional argument but 2 were given
# movie_rate = sum(map(lambda g: func(float(data[g][i]))*float(data[g][cols]), range(1,rows-1)))
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment