-
Notifications
You must be signed in to change notification settings - Fork 0
/
rf.py
23 lines (19 loc) · 889 Bytes
/
rf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from sklearn.ensemble import RandomForestClassifier
from sklearn import metrics
from sklearn.metrics import confusion_matrix, classification_report
class RF:
def __init__(self, feature_matrix_train, y_train):
self.feature_matrix_train = feature_matrix_train
self.y_train = feature_matrix_train
self.clf = RandomForestClassifier()
self.clf.fit(feature_matrix_train, y_train)
def predictRF(self,feature_matrix_test,y_test):
clf_predictions = self.clf.predict(feature_matrix_test)
test_accuracy = str(metrics.accuracy_score(y_test, clf_predictions))
print confusion_matrix(y_test, clf_predictions)
print '\n'
print classification_report(y_test, clf_predictions)
return test_accuracy
def predictRating(self,X_test):
clf_predictions = self.clf.predict(X_test)
return clf_predictions