-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
57 lines (29 loc) · 1.12 KB
/
model.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
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 30 13:49:59 2019
@author: rahul
"""
#Importing libraries
import pickle
from sklearn.ensemble import RandomForestClassifier
from sklearn import metrics
from sklearn.model_selection import cross_val_score
#Importing preprocessing file
from preprocessfinale11 import preprocessing
x_train,x_test,y_train,y_test=preprocessing()
#MODEL Training and Testing
print("...training model...")
classifier1=RandomForestClassifier(n_jobs=-1)
classifier1.fit(x_train,y_train)
y_pred=classifier1.predict(x_test)
#Saving the model(Pickle File)
filename = 'RF_model.sav'
pickle.dump(classifier1, open(filename, 'wb'))
#Train-Validation-Test
accuracies=cross_val_score(estimator=classifier1,X=x_train,y=y_train,cv=10)
#INSIGHTS & INFERENCES
print("Accuracy of the model: ",metrics.accuracy_score(y_test, y_pred))
print("Mean Accuracy: ",accuracies.mean())
print("Standard Deviation: ",accuracies.std())
#Confusion matrix
print(metrics.confusion_matrix(y_test.argmax(axis=1), y_pred.argmax(axis=1)))