Spaces:
Sleeping
Sleeping
Update core/plot.py
Browse files- core/plot.py +23 -5
core/plot.py
CHANGED
|
@@ -2,6 +2,7 @@ import matplotlib.pyplot as plt
|
|
| 2 |
import seaborn as sns
|
| 3 |
import pandas as pd
|
| 4 |
|
|
|
|
| 5 |
def plot_forecast(result):
|
| 6 |
forecast = result["forecast"]
|
| 7 |
actual = result["actual"]
|
|
@@ -14,7 +15,12 @@ def plot_forecast(result):
|
|
| 14 |
if next_pred:
|
| 15 |
ax.scatter(range(len(actual), len(actual) + len(next_pred)), next_pred, color="red", label="Next Prediction(s)", zorder=5)
|
| 16 |
for i, val in enumerate(next_pred):
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
ax.legend()
|
| 20 |
ax.set_title("Actual vs Forecasted Values")
|
|
@@ -44,12 +50,24 @@ def plot_future_forecast(df, result):
|
|
| 44 |
return fig
|
| 45 |
|
| 46 |
|
| 47 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 49 |
-
metrics = result['metrics']
|
| 50 |
-
sns.barplot(x=list(metrics.keys()), y=list(metrics.values()), ax=ax)
|
| 51 |
-
ax.set_title("
|
| 52 |
ax.grid(True)
|
|
|
|
| 53 |
return fig
|
| 54 |
|
| 55 |
|
|
|
|
| 2 |
import seaborn as sns
|
| 3 |
import pandas as pd
|
| 4 |
|
| 5 |
+
|
| 6 |
def plot_forecast(result):
|
| 7 |
forecast = result["forecast"]
|
| 8 |
actual = result["actual"]
|
|
|
|
| 15 |
if next_pred:
|
| 16 |
ax.scatter(range(len(actual), len(actual) + len(next_pred)), next_pred, color="red", label="Next Prediction(s)", zorder=5)
|
| 17 |
for i, val in enumerate(next_pred):
|
| 18 |
+
# Adjusted label positioning with background for clarity
|
| 19 |
+
ax.text(
|
| 20 |
+
len(actual) + i, val, f"{val:.2f}",
|
| 21 |
+
color="red", fontsize=8, ha='center', va='bottom',
|
| 22 |
+
bbox=dict(facecolor='white', alpha=0.8, edgecolor='red', boxstyle='round,pad=0.3')
|
| 23 |
+
)
|
| 24 |
|
| 25 |
ax.legend()
|
| 26 |
ax.set_title("Actual vs Forecasted Values")
|
|
|
|
| 50 |
return fig
|
| 51 |
|
| 52 |
|
| 53 |
+
def plot_metrics_r2(result):
|
| 54 |
+
fig, ax = plt.subplots(figsize=(6, 4))
|
| 55 |
+
metrics = {k: v for k, v in result['metrics'].items() if k in ['R2', 'MAPE']}
|
| 56 |
+
sns.barplot(x=list(metrics.keys()), y=list(metrics.values()), ax=ax, palette="Blues_d")
|
| 57 |
+
ax.set_title("R² and MAPE Metrics")
|
| 58 |
+
ax.set_ylim(-1, 1) # R² range, MAPE typically small
|
| 59 |
+
ax.grid(True)
|
| 60 |
+
plt.tight_layout()
|
| 61 |
+
return fig
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def plot_metrics_errors(result):
|
| 65 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 66 |
+
metrics = {k: v for k, v in result['metrics'].items() if k in ['RMSE', 'MAE']}
|
| 67 |
+
sns.barplot(x=list(metrics.keys()), y=list(metrics.values()), ax=ax, palette="Reds_d")
|
| 68 |
+
ax.set_title("RMSE and MAE Metrics")
|
| 69 |
ax.grid(True)
|
| 70 |
+
plt.tight_layout()
|
| 71 |
return fig
|
| 72 |
|
| 73 |
|