Im 아래 코드를 실행하면 두 번째 그래프의 숫자가 두 자리 정밀도 (0.3333 -> 33.33 %)로 백분율 형식으로 표시됩니다. 나는 배열의 람다 함수에서 '{percent, .2 %}'형식()을 사용하는 다른 버전의 톤을 시도했지만 모든 방법을 모릅니다. 모든 입력은 appriciated입니다! 사전에파이썬 그래프의 요소로 백분율 형식
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
from sklearn.tree import DecisionTreeClassifier
from sklearn import datasets
%matplotlib inline
iris = datasets.load_iris()
x = iris['data']
y = iris['target']
x = iris_x[:, :2]
clf_tree = DecisionTreeClassifier(random_state = 1)
fit_clf = clf_tree.fit(x, y)
y_pred_proba = fit_clf.predict_proba(x)
y_pred = fit_clf.predict(x)
conf_mat = confusion_matrix(y_true = y, y_pred = y_pred)
fig, ax = plt.subplots(figsize = (15, 9))
ax.matshow(conf_mat, cmap = plt.cm.Blues, alpha = 0.3)
for i in range(conf_mat.shape[0]):
for j in range(conf_mat.shape[1]):
ax.text(x = j, y = i,
s = conf_mat[i, j],
va = 'center',
ha = 'center')
plt.xlabel('Predicted')
plt.ylabel('Actual')
plt.show()
conf_mat_prc = conf_mat/len(y)
fig, ax = plt.subplots(figsize = (15, 9))
ax.matshow(conf_mat_prc, cmap = plt.cm.Blues, alpha = 0.3)
for i in range(conf_mat_prc.shape[0]):
for j in range(conf_mat_prc.shape[1]):
ax.text(x = j, y = i,
s = conf_mat_prc[i, j],
va = 'center',
ha = 'center')
plt.xlabel('Predicted % dist')
plt.ylabel('Actual % dist')
plt.show()
많은 감사,
--swepab
죄송합니다, 코드에 붙여 넣을 때 그 날의 실수였다. 내가 원하는 것은 모든 셀의 모든 요소에 대한 백분율 형식입니다. 예를 들어 셀 (0,0)에서 0.33 대신 33.33 %를 얻을 수 있습니다. – swepab
@swepab 지금 확인하십시오 – Yugi
승! 고마워, 도움을 많이! – swepab