Spaces:
Runtime error
Runtime error
Bachstelze commited on
Commit ·
eb5a0fb
1
Parent(s): c8963a5
init score board without png image
Browse files- requirements.txt +1 -0
- results/score_board.py +70 -0
requirements.txt
CHANGED
|
@@ -3,3 +3,4 @@ pandas>=2.0.0
|
|
| 3 |
numpy>=1.24.0
|
| 4 |
scikit-learn>=1.3.0
|
| 5 |
statsmodels>=0.14.0
|
|
|
|
|
|
| 3 |
numpy>=1.24.0
|
| 4 |
scikit-learn>=1.3.0
|
| 5 |
statsmodels>=0.14.0
|
| 6 |
+
matplotlib>=3.7.0
|
results/score_board.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import matplotlib.pyplot as plt
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
def create_score_board(weeks=None, scores=None, save_path=None, show=False):
|
| 5 |
+
"""
|
| 6 |
+
Create a score board plot for R^2 scores over weeks.
|
| 7 |
+
|
| 8 |
+
Parameters
|
| 9 |
+
----------
|
| 10 |
+
weeks : list, optional
|
| 11 |
+
List of week numbers. Default is [0, 1, 2].
|
| 12 |
+
scores : list, optional
|
| 13 |
+
List of R^2 scores. Default is [0, 0.51, 0.59].
|
| 14 |
+
save_path : str, optional
|
| 15 |
+
Path to save the plot. If None, the plot is not saved.
|
| 16 |
+
show : bool, optional
|
| 17 |
+
Whether to display the plot. Default is False.
|
| 18 |
+
|
| 19 |
+
Returns
|
| 20 |
+
-------
|
| 21 |
+
fig : matplotlib.figure.Figure
|
| 22 |
+
The generated figure object.
|
| 23 |
+
"""
|
| 24 |
+
if weeks is None:
|
| 25 |
+
weeks = [0, 1, 2]
|
| 26 |
+
if scores is None:
|
| 27 |
+
scores = [0, 0.51, 0.59]
|
| 28 |
+
|
| 29 |
+
# Create figure and axis
|
| 30 |
+
fig, ax = plt.subplots(figsize=(8, 6))
|
| 31 |
+
|
| 32 |
+
# Plot the data
|
| 33 |
+
ax.plot(weeks, scores, marker='o', linestyle='-', color='b', linewidth=2, markersize=8)
|
| 34 |
+
|
| 35 |
+
# Set labels and title
|
| 36 |
+
ax.set_xlabel('Week', fontsize=12)
|
| 37 |
+
ax.set_ylabel('R^2 Score', fontsize=12)
|
| 38 |
+
ax.set_title('R^2 Score Progression Over Weeks', fontsize=14, fontweight='bold')
|
| 39 |
+
|
| 40 |
+
# Set x-axis ticks to be exactly the weeks
|
| 41 |
+
ax.set_xticks(weeks)
|
| 42 |
+
ax.set_xticklabels([f'Week {w}' for w in weeks])
|
| 43 |
+
|
| 44 |
+
# Add grid for better readability
|
| 45 |
+
ax.grid(True, linestyle='--', alpha=0.7)
|
| 46 |
+
|
| 47 |
+
# Annotate each point with its score
|
| 48 |
+
for i, (x, y) in enumerate(zip(weeks, scores)):
|
| 49 |
+
ax.annotate(f'{y:.2f}', (x, y), textcoords="offset points", xytext=(0,10), ha='center')
|
| 50 |
+
|
| 51 |
+
# Adjust layout to prevent clipping
|
| 52 |
+
fig.tight_layout()
|
| 53 |
+
|
| 54 |
+
# Save the plot if save_path is provided
|
| 55 |
+
if save_path is not None:
|
| 56 |
+
# Ensure the directory exists
|
| 57 |
+
#os.makedirs(os.path.dirname(save_path), exist_ok=True)
|
| 58 |
+
# we save it into the main directory
|
| 59 |
+
fig.savefig(save_path, dpi=300)
|
| 60 |
+
print(f"Plot saved to {save_path}")
|
| 61 |
+
|
| 62 |
+
# Show the plot if requested
|
| 63 |
+
if show:
|
| 64 |
+
plt.show()
|
| 65 |
+
|
| 66 |
+
return fig
|
| 67 |
+
|
| 68 |
+
if __name__ == "__main__":
|
| 69 |
+
# Example usage with default data
|
| 70 |
+
fig = create_score_board(save_path='score_board.png', show=True)
|