๋ชจ๋ธ์ ์ฑ๋ฅ์ ๋ฐ์ง๋ ์งํ๋ ์ ํ๋(Accuracy)๋ง ์๋ ๊ฒ์ด ์๋๋ค.
Confusion Matrix์ ์๊ณ ๋ฆฌ์ฆ ๋ฐ ๋ชจ๋ธ์ ์ง๋จ,๋ถ๋ฅ,ํ๋ณ,์์ธก ๋ฅ๋ ฅ์ ํ๊ฐํ๊ธฐ ์ํ์ฌ ๊ณ ์๋ ํ๋ก, ์ค๋ฅํ๋ ฌ(error matrix)์ด๋ผ๊ณ ๋ ๋ถ๋ฆฌ๊ธฐ๋ ํ๋ค.
์ฑ๋ฅ์งํ๋ก ์ ํ๋(Accuracy), ์ ๋ฐ๋(Precision), ๋ฏผ๊ฐ๋(=์ฌํ์จ Recall), F1score ๋ฑ์ด ์์ผ๋ฉฐ, confusion matrix๋ก ํํ์ด ๊ฐ๋ฅํด์ง๋ค.
# ํผ๋ํ๋ ฌ
import matplotlib.pyplot as plt
my_data = []
y_pred_list = []
for data in prediction_list :
for data2 in data :
my_data.append(data2.item())
for data in label_list :
for data2 in data :
y_pred_list.append(data2.item())
from sklearn.metrics import confusion_matrix
confusion_matrix(my_data, y_pred_list)
import pandas as pd
import seaborn as sns
confusion_mx = pd.DataFrame(confusion_matrix(y_pred_list, my_data))
ax =sns.heatmap(confusion_mx, annot=True, fmt='g')
plt.title('confusion', fontsize=20)
plt.show()
from sklearn.metrics import precision_score, recall_score, f1_score, accuracy_score, classification_report
print(f"precision : {precision_score(my_data, y_pred_list, average='macro')}")
print(f"recall : {recall_score(my_data, y_pred_list, average='macro')}")
print(f"f1 score : {f1_score(my_data, y_pred_list, average='macro')}")
print(f"accuracy : {accuracy_score(my_data, y_pred_list)}")
f1_score_detail= classification_report(my_data, y_pred_list)
print(f1_score_detail)
์์ ๊ฐ์ ๋ฐฉ์์ผ๋ก ํผ๋ํ๋ ฌ์ ํ์ํ ์ ์์ผ๋ฉฐ, Label=3์ธ ๋ถ๋ฅ ๋ชจ๋ธ ํ์ต ๊ฒฐ๊ณผ๋ ์๋์ ๊ฐ๋ค.
1)https://manisha-sirsat.blogspot.com/2019/04/confusion-matrix.html
https://namu.wiki/w/%ED%98%BC%EB%8F%99%ED%96%89%EB%A0%AC
728x90
๋ฐ์ํ