Search

모델 정확도 검증 시각화 예시

1. 사용자 지정 함수 정확도

import numpy as np ##### 평가산식 : ACCURACY(정확도) ##### def ACC(y_true, pred): score = np.mean(y_true==pred) return score ##### 모델 검증 시각화 ##### def make_plot(y_true, pred): acc = ACC(y_true, pred) df_validation = pd.DataFrame({'y_true':y_true, 'y_pred':pred}) # 검증 데이터 정답지('y_true') 빈도수 (sorted) df_validation_count = pd.DataFrame(df_validation['y_true'].value_counts().sort_index()) # 검증 데이터 예측치('y_pred') 빈도수 (sorted) df_pred_count = pd.DataFrame(df_validation['y_pred'].value_counts().sort_index()) # pd.concat - 검증 데이타 정답지, 예측치 빈도수 합치기 df_val_pred_count = pd.concat([df_validation_count,df_pred_count], axis=1).fillna(0) ############################################################ # 그래프 그리기 ############################################################ x = df_validation_count.index y_true_count = df_val_pred_count['y_true'] y_pred_count = df_val_pred_count['y_pred'] width = 0.35 plt.figure(figsize=(5,3),dpi=150) plt.title('ACC : ' + str(acc)[:6]) plt.xlabel('quality') plt.ylabel('count') p1 = plt.bar([idx-width/2 for idx in x], y_true_count, width, label='real') p2 = plt.bar([idx+width/2 for idx in x], y_pred_count, width, label='pred') plt.legend() plt.show()
Python
복사