From 19be35cd9de1e845bbb6fee5bb4676083152d8e5 Mon Sep 17 00:00:00 2001 From: Jack Huang Date: Tue, 21 Aug 2018 15:54:28 +0800 Subject: [PATCH] fix transform issue 1. change fit_transform to transform for test data, it will increase F1 score 2. Add output for confusion_matrix and classification_report to understand the classification result --- Code/Day 13_SVM.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Code/Day 13_SVM.py b/Code/Day 13_SVM.py index df9eeda..d65ca85 100644 --- a/Code/Day 13_SVM.py +++ b/Code/Day 13_SVM.py @@ -18,7 +18,7 @@ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, rand from sklearn.preprocessing import StandardScaler sc = StandardScaler() X_train = sc.fit_transform(X_train) -X_test = sc.fit_transform(X_test) +X_test = sc.transform(X_test) #Fitting SVM to the Training set from sklearn.svm import SVC @@ -30,7 +30,10 @@ y_pred = classifier.predict(X_test) #Making the Confusion Matrix from sklearn.metrics import confusion_matrix +from sklearn.metrics import classification_report cm = confusion_matrix(y_test, y_pred) +print(cm) +print(classification_report(y_test, y_pred)) #Visualising the Training set results from matplotlib.colors import ListedColormap