51 lines
1.9 KiB
Python
51 lines
1.9 KiB
Python
import os
|
|
import json
|
|
import matplotlib.pyplot as plt
|
|
import pandas as pd
|
|
import seaborn as sns
|
|
|
|
output_dir = 'output'
|
|
model_dirs = [d for d in os.listdir(output_dir) if os.path.isdir(os.path.join(output_dir, d)) and os.path.exists(os.path.join(output_dir, d, 'compare.json'))]
|
|
model_dirs.sort()
|
|
|
|
if not model_dirs:
|
|
print("데이터를 찾을 수 없습니다.")
|
|
exit()
|
|
|
|
fig, axes = plt.subplots(len(model_dirs), 1, figsize=(15, 6 * len(model_dirs)), sharex=False)
|
|
if len(model_dirs) == 1:
|
|
axes = [axes]
|
|
|
|
for i, model in enumerate(model_dirs):
|
|
json_path = os.path.join(output_dir, model, 'compare.json')
|
|
with open(json_path, 'r', encoding='utf-8') as f:
|
|
data = json.load(f)
|
|
df = pd.DataFrame(data.get('details', []))
|
|
|
|
# 에러 절댓값 계산 및 내림차순 정렬
|
|
df['abs_error'] = df['error'].abs()
|
|
df = df.sort_values('abs_error', ascending=False).reset_index(drop=True)
|
|
|
|
ax = axes[i]
|
|
# y축에 abs_error를 사용하여 양수 영역만 표시
|
|
sns.scatterplot(data=df, x=df.index, y='abs_error', ax=ax, alpha=0.6, s=20, color='darkorange')
|
|
|
|
ax.set_title(f'Model: {model} (Sorted by Absolute Error)', fontsize=15, fontweight='bold')
|
|
ax.set_ylabel('Absolute Error (|Actual - Predicted|)', fontsize=12)
|
|
ax.set_xlabel(f'Songs (Ordered by Error Magnitude)', fontsize=12)
|
|
|
|
# 가이드 라인 (오차 0.2, 0.5, 1.0 단위)
|
|
ax.axhline(0.2, color='green', linestyle='--', linewidth=0.8, alpha=0.5, label='Target (0.2)')
|
|
ax.axhline(0.5, color='blue', linestyle='--', linewidth=0.8, alpha=0.5)
|
|
ax.axhline(1.0, color='red', linestyle='--', linewidth=0.8, alpha=0.5)
|
|
|
|
# y축을 0부터 시작하도록 설정
|
|
ax.set_ylim(0, 3.5)
|
|
ax.set_xticks([]) # x축 라벨 제거
|
|
ax.grid(True, axis='y', alpha=0.3)
|
|
|
|
plt.tight_layout()
|
|
output_image = 'abs_error_analysis.png'
|
|
plt.savefig(output_image)
|
|
print(f"절댓값 에러 정렬 그래프가 {output_image}에 저장되었습니다.")
|