“Sklearn -Plot -Verwirrungsmatrix” Code-Antworten

Sklearn -Plot -Verwirrungsmatrix

import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix, plot_confusion_matrix

clf = # define your classifier (Decision Tree, Random Forest etc.)
clf.fit(X, y) # fit your classifier

# make predictions with your classifier
y_pred = clf.predict(X)         
# optional: get true negative (tn), false positive (fp)
# false negative (fn) and true positive (tp) from confusion matrix
M = confusion_matrix(y, y_pred)
tn, fp, fn, tp = M.ravel() 
# plotting the confusion matrix
plot_confusion_matrix(clf, X, y)
plt.show()
wolf-like_hunter

Importieren Sie sklearn.metrics aus plot_confusion_matrix

from sklearn.metrics import plot_confusion_matrix
sbmthakur

Verwirrungsmatrix darstellen

from sklearn.metrics import confusion_matrix
matrix_confusion = confusion_matrix(y_test, y_pred)
sns.heatmap(matrix_confusion, square=True, annot=True, cmap='Blues', fmt='d', cbar=False
JJSSEECC

Sklearn -Plot -Verwirrungsmatrix

from sklearn.linear_model import LogisticRegression
from sklearn.metrics import  plot_confusion_matrix
clf = LogisticRegression()
clf.fit(X_train,y_train)
disp = plot_confusion_matrix(clf,X_test,y_test,cmap="Blues",values_format='.3g')
plt.tight_layout()
plt.ylabel('True label')
plt.xlabel('Predicted label')
Thankful Tuatara

Verwirrungsmatrix mit Etiketten Sklearn

import pandas as pd
y_true = pd.Series([2, 0, 2, 2, 0, 1, 1, 2, 2, 0, 1, 2])
y_pred = pd.Series([0, 0, 2, 1, 0, 2, 1, 0, 2, 0, 2, 2])

pd.crosstab(y_true, y_pred, rownames=['True'], colnames=['Predicted'], margins=True)
DS in Training

Ähnliche Antworten wie “Sklearn -Plot -Verwirrungsmatrix”

Fragen ähnlich wie “Sklearn -Plot -Verwirrungsmatrix”

Weitere verwandte Antworten zu “Sklearn -Plot -Verwirrungsmatrix” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen