-
Notifications
You must be signed in to change notification settings - Fork 0
/
similarity.py
48 lines (31 loc) · 1.13 KB
/
similarity.py
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
import pandas as pd
from itertools import combinations
from collections import Counter
def read_file(file, cols):
return pd.read_csv(file, usecols=cols)
def remove_dislikes(df, col):
return df[df[col].values]
def merge_dfs(df_1, df_2):
return pd.merge(left=df_1, right=df_2)
def get_groupings(df, col_1, col_2):
return df.groupby(col_1).apply(lambda x: x[col_2].unique())
def get_values_list(df):
return [x for x in df.values]
def get_score(list):
count = Counter()
for sublist in list:
count.update(combinations(sublist, 2))
return count.most_common()[0]
reactions = read_file('data/reactions.csv', [
'user_id', 'job_id', 'direction', 'time'
])
jobs = read_file('data/jobs.csv', [
'job_id', 'company_id'
])
merged = merge_dfs(jobs, remove_dislikes(reactions, 'direction'))
grouped_jobs = get_groupings(merged, 'job_id', 'user_id')
grouped_companies = get_groupings(merged, 'user_id', 'company_id')
user_score = get_score(get_values_list(grouped_jobs))
company_score = get_score(get_values_list(grouped_companies))
print('User score: ', user_score)
print('Company score: ', company_score)