Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

confusion matrix for classification

# 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))
Comment

PREVIOUS NEXT
Code Example
Python :: saleor docker development 
Python :: flask blueprint 
Python :: mse python 
Python :: taking array input in python 
Python :: python-telegram-bot send file 
Python :: print for loop in same line python 
Python :: Get current cursor type and color Tkinter Python 
Python :: how to get a summary of a column in python 
Python :: plus in python 
Python :: read and write to file python 
Python :: remove initial space python 
Python :: __str__ method python 
Python :: read data from excel and plot in python 
Python :: find frequency of numbers in list python 
Python :: numpy diff 
Python :: how to stop all pygame mixer sound 
Python :: logging 
Python :: How to Get the Intersection of Sets in Python 
Python :: python finally keyword 
Python :: substract list python 
Python :: python session set cookies 
Python :: django oauth toolkit permanent access token 
Python :: python if null 
Python :: beautifulsoup find element by partial text 
Python :: telegram bot webhook python 
Python :: scikit learn roc curve 
Python :: scroll to element selenium python 
Python :: pandas do not display index 
Python :: python unittest discover 
Python :: Using Python, getting the name of files in a zip archive 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =