forked from nishantrathi100/Yelp-Data-Mining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobalModel.py
35 lines (28 loc) · 1.12 KB
/
globalModel.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
from testDataDirectory import *
from globalTrainDataDirectory import *
from util import *
from sklearn.neighbors import KNeighborsRegressor
from globalTrainDataDirectory import *
from SentimentAnalysis import *
from NMFModel import *
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVR
clfs = [ LogisticRegression(),
KNeighborsRegressor(n_neighbors=3),
SVR(C=1.0, cache_size=200, coef0=0.0, degree=3, epsilon=0.2, gamma='auto',kernel='rbf', max_iter=-1, shrinking=True, tol=0.001, verbose=False)
]
clf_names = ['Logistic Regression','KNeighbors Regressor','SVR']
neigh=[]
train_ratings= map(float,getTrainGlobalAllActualRating())
for (i, clf_) in enumerate(clfs):
neigh.append(clf_.fit(getTrainGlobalAllDocNMF(), train_ratings))
#neigh = KNeighborsRegressor(n_neighbors=3)
#neigh.fit(getTrainGlobalAllDocNMF(), map(float,getTrainGlobalAllActualRating()))
def predict_global_rating(reviewCSR):
reviewCSR= [reviewCSR]
ans = {}
for (i, clf_) in enumerate(clfs):
predicted = neigh[i].predict(reviewCSR)
ans[clf_names[i]] = predicted[0]
return ans
#return ans