Created
November 9, 2017 02:15
-
-
Save 64lines/99ddbd071c791d8df477befbd656f2d7 to your computer and use it in GitHub Desktop.
[PYTHON][SKLEARN] Clasification Report and Confussion Matrix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Import necessary modules | |
| from sklearn.metrics import classification_report | |
| from sklearn.metrics import confusion_matrix | |
| # Create training and test set | |
| X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.4, random_state=42) | |
| # Instantiate a k-NN classifier: knn | |
| knn = KNeighborsClassifier(n_neighbors=6) | |
| # Fit the classifier to the training data | |
| knn.fit(X_train, y_train) | |
| # Predict the labels of the test data: y_pred | |
| y_pred = knn.predict(X_test) | |
| # Generate the confusion matrix and classification report | |
| print(confusion_matrix(y_test, y_pred)) | |
| print(classification_report(y_test, y_pred)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment