Download predictor/chart_plotter.py from Pushpak21/SuperKart_Sales_Forecast_Frontend: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/Pushpak21/SuperKart_Sales_Forecast_Frontend/resolve/main/predictor/chart_plotter.py
- Command line
-
hf download hf://spaces/Pushpak21/SuperKart_Sales_Forecast_Frontend/predictor/chart_plotter.py
-
curl -L -o chart_plotter.py https://huggingface.co/spaces/Pushpak21/SuperKart_Sales_Forecast_Frontend/resolve/main/predictor/chart_plotter.py
1.36 kB
| import altair as alt | |
| import pandas as pd | |
| import streamlit as st | |
| def plot_actual_vs_predicted(df: pd.DataFrame): | |
| if "Product_Store_Sales_Total" not in df.columns or "Predicted_Sales" not in df.columns: | |
| st.warning("ℹ️ Required columns not found for plotting.") | |
| return | |
| plot_df = df[["Product_Store_Sales_Total", "Predicted_Sales"]].dropna() | |
| if plot_df.empty: | |
| st.info("ℹ️ Not enough valid rows for plotting.") | |
| return | |
| x_min = plot_df["Product_Store_Sales_Total"].min() | |
| x_max = plot_df["Product_Store_Sales_Total"].max() | |
| # Scatter plot | |
| scatter = alt.Chart(plot_df).mark_circle(size=60, color='steelblue').encode( | |
| x=alt.X("Product_Store_Sales_Total", title="Actual Sales"), | |
| y=alt.Y("Predicted_Sales", title="Predicted Sales"), | |
| tooltip=["Product_Store_Sales_Total", "Predicted_Sales"] | |
| ) | |
| # Parity line (y = x) | |
| parity_line = alt.Chart(pd.DataFrame({ | |
| 'x': [x_min, x_max], | |
| 'y': [x_min, x_max] | |
| })).mark_line(color='red', strokeDash=[5, 5]).encode( | |
| x='x:Q', | |
| y='y:Q' | |
| ) | |
| # Combine | |
| chart = (scatter + parity_line).properties( | |
| width=700, | |
| height=400, | |
| title="Actual vs Predicted Sales" | |
| ).configure_title(fontSize=18, anchor='middle') | |
| st.altair_chart(chart, use_container_width=True) | |