Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
TMP-23-105
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
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
K.Tharmikan
TMP-23-105
Commits
2ea81741
Commit
2ea81741
authored
Jun 02, 2023
by
M.A. Miqdad Ali Riza
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
4137645a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
0 deletions
+35
-0
Wishlist_create.py
Wishlist_create.py
+35
-0
No files found.
Wishlist_create.py
0 → 100644
View file @
2ea81741
import
pandas
as
pd
import
numpy
as
np
from
sklearn.metrics.pairwise
import
cosine_similarity
# Load the song data
song_ratings
=
pd
.
read_csv
(
"song_ratings.csv"
)
# Create a user-song matrix
user_song_ratings
=
song_ratings
.
pivot_table
(
index
=
'user_id'
,
columns
=
'song_id'
,
values
=
'rating'
)
user_song_ratings
.
fillna
(
0
,
inplace
=
True
)
# Calculate the cosine similarity
song_similarity
=
cosine_similarity
(
user_song_ratings
.
T
)
# Define a function to generate a playlist based on a user's wish list
def
generate_playlist
(
wish_list
,
num_songs
=
10
):
invalid_users
=
set
(
wish_list
)
-
set
(
user_song_ratings
.
index
)
if
invalid_users
:
print
(
f
"Song IDs: {invalid_users}"
)
return
None
user_ratings
=
user_song_ratings
.
loc
[
wish_list
]
.
values
song_ratings_mean
=
user_song_ratings
.
mean
(
axis
=
0
)
.
values
.
reshape
(
1
,
-
1
)
user_ratings_centered
=
user_ratings
-
song_ratings_mean
song_scores
=
np
.
dot
(
user_ratings_centered
,
song_similarity
)
/
np
.
sum
(
np
.
abs
(
song_similarity
),
axis
=
0
)
top_song_indices
=
np
.
argsort
(
-
song_scores
)[:
num_songs
]
top_song_ids
=
user_song_ratings
.
columns
[
top_song_indices
]
.
tolist
()
return
top_song_ids
wish_list
=
[
3
,
5
]
playlist
=
generate_playlist
(
wish_list
,
num_songs
=
5
)
if
playlist
is
not
None
:
playlist_songs
=
song_ratings
[
song_ratings
[
'song_id'
]
.
isin
(
playlist
)][
'song_id'
]
print
(
playlist_songs
)
M.A. Miqdad Ali Riza
@it20276614_Miqdad
·
Sep 06, 2023
Developer
song_ratings.csv
Code.py
[song_ratings.csv](/uploads/3d6d0d7d150ce37ad81e0d5b85c1b534/song_ratings.csv) [Code.py](/uploads/3d8ff01241e2563f77be30ea0891f74e/Code.py)
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