-
Notifications
You must be signed in to change notification settings - Fork 0
/
recommendation
32 lines (22 loc) · 906 Bytes
/
recommendation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 20 15:49:47 2018
@author: vivekmishra
"""
from sklearn.metrics.pairwise import cosine_similarity
import pandas as pd
#id = 'iUdgD8kYU-E'
class rec:
def recommendation(self,id,feature_df):
cluster_no = feature_df[feature_df['id'] == feature_df]['clusters']
cluster_no = cluster_no.item()
#select data of that cluster
slice_df = feature_df[feature_df['clusters'] == cluster_no]
#cosine similarity matrix
cos_sim = cosine_similarity(slice_df.values)
df_temp = pd.DataFrame(cos_sim, columns=slice_df.index.values, index=slice_df.index)
interest_list = df_temp[id]
index_min = list(interest_list.argsort()[:3].keys())
index_max = list(interest_list.argsort()[::-1][:4].keys())
return index_min,index_max