pp

pp
 avatar
unknown
python
a year ago
1.4 kB
8
Indexable
import json
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

# Load JSON data from file
file_path = '/mnt/data/image.png'  # Update this path to the actual JSON file path

with open(file_path, 'r') as file:
    data = json.load(file)

# Prepare data for heatmap
models = []
lengths = []
columns = []
values = []

for model_name, length_data in data.items():
    for length, metrics in length_data.items():
        row_name = f"{model_name} ({length})"
        for metric, vals in metrics.items():
            models.append(row_name)
            lengths.append(f"{metric}(r)")
            values.append(vals[0])
            models.append(row_name)
            lengths.append(f"{metric}(f)")
            values.append(vals[1])

# Create pivot table
data_matrix = np.array(values).reshape(len(data) * len(metrics) * 2, len(metrics))
heatmap_data = pd.DataFrame(data_matrix, index=models, columns=[f"{metric}(r)" for metric in metrics.keys()] + [f"{metric}(f)" for metric in metrics.keys()])

# Plot heatmap
plt.figure(figsize=(15, 10))
sns.heatmap(heatmap_data, annot=True, cmap='coolwarm', center=0, linewidths=.5, cbar_kws={"shrink": .8})
plt.title('Heatmap of Model Metrics')
plt.xlabel('Metrics')
plt.ylabel('Models')
plt.xticks(rotation=45)
plt.yticks(rotation=0)
plt.tight_layout()

# Show plot
plt.show()
Editor is loading...
Leave a Comment