-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathproperties_1.py
53 lines (46 loc) · 1.87 KB
/
properties_1.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
from sklearn import metrics
from sklearn.metrics import roc_curve, auc
import matplotlib.pyplot as plt
def plot_confusion_metrix(y_test,model_test):
cm = metrics.confusion_matrix(y_test, model_test)
plt.figure(1)
plt.clf()
plt.imshow(cm, interpolation='nearest', cmap=plt.cm.Wistia)
classNames = ['Nondemented','Demented']
plt.title('Confusion Matrix')
plt.ylabel('True label')
plt.xlabel('Predicted label')
tick_marks = np.arange(len(classNames))
plt.xticks(tick_marks, classNames)
plt.yticks(tick_marks, classNames)
s = [['TN','FP'], ['FN', 'TP']]
for i in range(2):
for j in range(2):
plt.text(j,i, str(s[i][j])+" = "+str(cm[i][j]))
plt.show()
def report_performance(model,model_test,y_test):
#model_test = model.predict(X_test)
print("\n\nConfusion Matrix:")
print("{0}".format(metrics.confusion_matrix(y_test, model_test)))
print("\n\nClassification Report: ")
print(metrics.classification_report(y_test, model_test))
#cm = metrics.confusion_matrix(y_test, model_test)
plot_confusion_metrix(y_test, model_test)
def roc_curves(model,X_test,y_test):
predictions_test = model.predict(X_test)
fpr, tpr, thresholds = roc_curve(predictions_test,y_test)
roc_auc = auc(fpr, tpr)
plt.figure()
plt.plot(fpr, tpr, color='darkorange', lw=1, label='ROC curve (area = %0.2f)' % roc_auc)
plt.plot([0, 1], [0, 1], color='navy', lw=2, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver operating characteristic')
plt.legend(loc="lower right")
plt.show()
def accuracy(model,X_test):
pred = model.predict(X_test)
accu = metrics.accuracy_score(y_test,pred)
print("\nAcuuracy Of the Model: ",accu,"\n\n")