Spaces:
Sleeping
Sleeping
Commit
·
dbdc0fc
1
Parent(s):
6bd2e39
Update Recommender.py
Browse files- Recommender.py +5 -3
Recommender.py
CHANGED
@@ -3,9 +3,11 @@ import pandas as pd
|
|
3 |
from sklearn.metrics.pairwise import cosine_similarity
|
4 |
|
5 |
class Recommender :
|
6 |
-
def __init__(self, title_vec_col, content_vec_col
|
7 |
self.title_vec_col = title_vec_col
|
8 |
self.content_vec_col = content_vec_col
|
|
|
|
|
9 |
self.id_col = id_col
|
10 |
|
11 |
def calculate_recom_scores (self, k, similarities) :
|
@@ -56,10 +58,10 @@ class Recommender :
|
|
56 |
|
57 |
# return result[self.id_col, :].tolist()
|
58 |
|
59 |
-
def recommend_k(self, table, k,
|
60 |
|
61 |
data = np.array(list(zip(*table)))
|
62 |
-
idx = int(data[0][data[self.
|
63 |
|
64 |
titles = self.str2arr(data[self.title_vec_col, :])
|
65 |
contents = self.str2arr(data[self.content_vec_col, :])
|
|
|
3 |
from sklearn.metrics.pairwise import cosine_similarity
|
4 |
|
5 |
class Recommender :
|
6 |
+
def __init__(self, id_col, title_col, content_col, title_vec_col, content_vec_col):
|
7 |
self.title_vec_col = title_vec_col
|
8 |
self.content_vec_col = content_vec_col
|
9 |
+
self.title_col = title_col
|
10 |
+
self.content_col = content_col
|
11 |
self.id_col = id_col
|
12 |
|
13 |
def calculate_recom_scores (self, k, similarities) :
|
|
|
58 |
|
59 |
# return result[self.id_col, :].tolist()
|
60 |
|
61 |
+
def recommend_k(self, table, k, title):
|
62 |
|
63 |
data = np.array(list(zip(*table)))
|
64 |
+
idx = int(data[0][data[self.title_col] == title].item())
|
65 |
|
66 |
titles = self.str2arr(data[self.title_vec_col, :])
|
67 |
contents = self.str2arr(data[self.content_vec_col, :])
|