-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.py
More file actions
88 lines (71 loc) · 2.26 KB
/
analysis.py
File metadata and controls
88 lines (71 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import json
import numpy as np
import os
from datetime import datetime
# Create a folder with a timestamp in the name
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
# Adjust these paths as needed
output_folder = f"chess_metrics_{timestamp}"
file_path = r'chess_metrics_sft_atm_sl5_mnt100.jsonl'
os.makedirs(output_folder, exist_ok=True)
# Function to read JSONL file
def read_jsonl(file_path):
data = []
with open(file_path, 'r') as f:
for line in f:
data.append(json.loads(line))
return data
# Read data
try:
data = read_jsonl(file_path)
print(f"Successfully loaded {len(data)} records")
except FileNotFoundError:
raise FileNotFoundError("Results file not found.")
# Create DataFrame
df = pd.DataFrame(data)
# Calculate legal move fraction
df['legal_move_fraction'] = df['num_legal_moves_suggested'] / df['total_moves']
# Extract model name without path for better visualization
df['model_short_name'] = df['model_name'].apply(lambda x: x.split('/')[-1])
# Set up the visualization
sns.set_theme(style="whitegrid")
# Metrics to plot
metrics = [
('move_accuracy', 'Move Accuracy'),
('legal_move_fraction', 'Legal Move Fraction'),
('avg_move_quality', 'Average Move Quality')
]
# Plot each metric in a separate figure
for metric, title in metrics:
plt.figure(figsize=(10, 6))
# Create grouped bar chart
ax = sns.barplot(
x='model_short_name',
y=metric,
hue='prompt_method',
data=df,
palette="viridis"
)
# Enhance readability
plt.title(title, fontsize=16)
plt.xlabel('Model', fontsize=12)
plt.ylabel(title, fontsize=12)
plt.xticks(rotation=45)
plt.legend(title='Prompt Method')
# Add value labels on bars
for p in ax.patches:
ax.annotate(
f'{p.get_height():.2f}',
(p.get_x() + p.get_width() / 2., p.get_height()),
ha='center', va='bottom',
fontsize=8, rotation=0
)
# Save each plot separately
plot_path = os.path.join(output_folder, f'{metric}_bar_chart.png')
plt.tight_layout()
plt.savefig(plot_path, dpi=300)
plt.show()
print(f"Plots saved in folder: {output_folder}")