Невозможно ничего напечатать во второй строке матрицы путаницы. ⇐ Python
Невозможно ничего напечатать во второй строке матрицы путаницы.
Can anyone please help! I tried printing confusion matrix, but not able to get the values in row 2. I am not able to print anything in row 2 for the KNN Model trained.
import matplotlib.pyplot as plt from sklearn.neighbors import KNeighborsClassifier from sklearn.metrics import accuracy_score, classification_report, confusion_matrix def plot_confusion_matrix(y_test, y_pred): cm = confusion_matrix(y_test, y_pred) sns.heatmap(cm, annot=True, fmt="d", cmap="Blues") plt.xlabel("Predicted") plt.ylabel("Actual") plt.title("Confusion Matrix") plt.xticks([0, 1], ["Edible", "Poisonous"]) plt.yticks([0, 1], ["Edible", "Poisonous"]) plt.show() target_names = ["Edible", "Poisonous"] knn_classifier = KNeighborsClassifier(n_neighbors=5) knn_classifier.fit(X_train, y_train) y_pred = knn_classifier.predict(X_test) print(classification_report(y_test, y_pred, target_names=target_names)) conf_matrix = confusion_matrix(y_test, y_pred) plt.figure(figsize=(8, 6)) sns.heatmap(conf_matrix, annot=True, fmt='d', cmap='Blues', xticklabels=target_names, yticklabels=target_names) plt.xlabel('Predicted') plt.ylabel('Actual') plt.title('Confusion Matrix') plt.show() accuracy = accuracy_score(y_test, y_pred) print("Accuracy:", accuracy)```
Источник: https://stackoverflow.com/questions/781 ... ion-matrix
Can anyone please help! I tried printing confusion matrix, but not able to get the values in row 2. I am not able to print anything in row 2 for the KNN Model trained.
import matplotlib.pyplot as plt from sklearn.neighbors import KNeighborsClassifier from sklearn.metrics import accuracy_score, classification_report, confusion_matrix def plot_confusion_matrix(y_test, y_pred): cm = confusion_matrix(y_test, y_pred) sns.heatmap(cm, annot=True, fmt="d", cmap="Blues") plt.xlabel("Predicted") plt.ylabel("Actual") plt.title("Confusion Matrix") plt.xticks([0, 1], ["Edible", "Poisonous"]) plt.yticks([0, 1], ["Edible", "Poisonous"]) plt.show() target_names = ["Edible", "Poisonous"] knn_classifier = KNeighborsClassifier(n_neighbors=5) knn_classifier.fit(X_train, y_train) y_pred = knn_classifier.predict(X_test) print(classification_report(y_test, y_pred, target_names=target_names)) conf_matrix = confusion_matrix(y_test, y_pred) plt.figure(figsize=(8, 6)) sns.heatmap(conf_matrix, annot=True, fmt='d', cmap='Blues', xticklabels=target_names, yticklabels=target_names) plt.xlabel('Predicted') plt.ylabel('Actual') plt.title('Confusion Matrix') plt.show() accuracy = accuracy_score(y_test, y_pred) print("Accuracy:", accuracy)```
Источник: https://stackoverflow.com/questions/781 ... ion-matrix
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Рассчитайте точность, полноту, точность и сбалансированную точность из матрицы путаницы.
Anonymous » » в форуме Python - 0 Ответы
- 38 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Несоответствие между результатами перекрестной проверки и метриками матрицы путаницы
Anonymous » » в форуме Python - 0 Ответы
- 24 Просмотры
-
Последнее сообщение Anonymous
-