-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
66 lines (49 loc) · 1.93 KB
/
app.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
49
50
51
52
53
54
55
56
57
import sys
from algorithm.dataSet import DataSet
from algorithm.knn import Knn
from util.errorCheck import getRating, MAE
from plots.bubblePlot import BubblePlot
from settings import SYS_ENCODING_UTF, JSON_FILE_PATH, JSON_FILE_NAME, PLOT_RESULTS, DISTANCE_TO_FILTER, TIME_TO_FILTER, \
KNN_NEIGHBOURS, ENABLE_DISTANCE_FILTER, ENABLE_TIME_FILTER
reload(sys)
sys.setdefaultencoding(SYS_ENCODING_UTF)
dataSet = DataSet(JSON_FILE_PATH + JSON_FILE_NAME)
dataSet.loadRawData()
dataSet.processBusinessModels()
print("\nNumber of Business Models: %s" % len(dataSet.businessModels))
dataSet.sliceData()
dataSet.trainUserModel()
if ENABLE_TIME_FILTER:
dataSet.timeFilterBusinessModel(TIME_TO_FILTER)
if ENABLE_DISTANCE_FILTER:
dataSet.distFilterBusinessModel(DISTANCE_TO_FILTER)
print("Test Data: %s" % len(dataSet.testData))
print("Training Data: %s \n" % len(dataSet.trainingData))
knn = Knn()
knn.inputData = dataSet
predictions = knn.getNearestNeighbours(KNN_NEIGHBOURS)
for index, p in enumerate(predictions):
print ("Name: %s\n" \
"User Rating: %s\n" \
"Business Rating: %s\n" \
"Prediction Score: %s\n" \
"Predicted Rating: %s \n" \
"Prediction Rank: %s\n"
% (p.name,
p.stars,
p.findHighestUserRating(dataSet.businessModels),
p.predictionScore,
getRating(round(p.predictionScore)),
index + 1))
print "Mean Absolute Error (FILTERS: %s): %s" % ((ENABLE_DISTANCE_FILTER or ENABLE_TIME_FILTER), MAE(predictions, dataSet.businessModels))
if ENABLE_DISTANCE_FILTER: print "DISTANCE FILTER: ON"
else: print "DISTANCE FILTER: OFF"
if ENABLE_TIME_FILTER: print "TIME FILTER: ON"
else: print "TIME FILTER: OFF"
if PLOT_RESULTS:
bp = BubblePlot()
bp.testData = dataSet.testData
bp.user = dataSet.userData
bp.predictions = predictions
bp.allBusinessModels = dataSet.businessModels
bp.generate()