-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodelabstract.py
More file actions
74 lines (46 loc) · 1.25 KB
/
modelabstract.py
File metadata and controls
74 lines (46 loc) · 1.25 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
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 20 00:52:40 2019
@author: lifel
"""
import json
import numpy as np
import modeltrain as mt
x = mt.findgoodinps()
add = []
for i in range(10):
_c = mt.makemodel(x[i])
add.append(_c)
#%%
with open('buisnessoutput.txt') as json_file:
bo = json.load(json_file)
business = np.array([list(v) for v in bo.values()])
business = business.astype(float)
#%%
def meanModel(users, business):
x = np.array(users)
xmean = np.mean(x, axis=0)
xmeanT = np.transpose(xmean)
xScored = np.matmul(business, xmeanT)
xTop5 = np.argsort(xScored)[-5:]
return xTop5.tolist()
def medianModel(users, business):
x = np.array(users)
xmean = np.median(x, axis=0)
xmeanT = np.transpose(xmean)
xScored = np.matmul(business, xmeanT)
xTop5 = np.argsort(xScored)[-5:]
return xTop5.tolist()
def avgMeanMedian(users, business):
x = np.array(users)
xmean = (np.median(x, axis=0) + np.mean(x, axis=0))/2
xmeanT = np.transpose(xmean)
xScored = np.matmul(business, xmeanT)
xTop5 = np.argsort(xScored)[-5:]
return xTop5.tolist()
a1 = meanModel(add,business)
a2 = medianModel(add,business)
a3 = avgMeanMedian(add,business)
print(a1)
print(a2)
print(a3)