-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinterface.py
More file actions
75 lines (57 loc) · 2.2 KB
/
interface.py
File metadata and controls
75 lines (57 loc) · 2.2 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import numpy as np
import pandas as pd
def get_user_name():
'''
Getting the username that wil be use it in the recommendation system
'''
x = input("Please, enter your username:\n")
return x
def get_number(top_25_list):
'''
Getting the number of subredits that the user likes
'''
print("Hello user, welcome to our great recommender program!\n\nHere are some popular subreddits if you are having trouble selecting:\n\n" , top_25_list)
while True:
try:
x = int(input("How many subreddits do you want to give our recommender system? Please enter a number:\n"))
break
except ValueError:
print("Oops! That was no valid number. Try again...")
return x
def get_subreddits(x, df):
'''
Processing the subreddits
'''
d = {}
n = x
df.columns = map(str.lower, df.columns)
columns = [e.lower() for e in df.columns]
print("Please type your subreddits considering the priority. Start with what you like more.")
while n>0:
subreddit = input("\nEnter a subreddit:\n").lower()
if subreddit in columns:
keys = subreddit
values = n/x - 0.05
d[keys] = values
n -= 1
else:
print("Your subreddit it's not in our data, please enter the subreddit again.")
return d
def get_subreddits_rating_list(d, df): # to Ray
'''
Returning a list of ratings by subreddits
(Kipping the consistency between the position of the elements in the list and trainning data columns)
This is the list that will be use it to predict
'''
new_df = pd.DataFrame()
new_df = df.append(d, ignore_index=True).fillna(0)
return list(new_df.iloc[-1].values)
def get_rating_data_frame(d, user_name): # to Jose
'''
Returning a dataframe - ratings by subreddits
This is the dataframe that will be used in the recommender system
'''
new_df = pd.DataFrame.from_dict(d, orient='index').reset_index()
new_df['username'] = user_name
new_df.rename(columns={"index": "subreddit", 0: "rating"}, inplace = True)
return new_df