File size: 1,357 Bytes
89bdc35 d893363 89bdc35 d893363 89bdc35 24f9aea 89bdc35 24f9aea d893363 55f4726 e57cfc9 d893363 89bdc35 24f9aea 7459dcd e57cfc9 d893363 55fb607 d893363 55fb607 d893363 55fb607 d893363 |
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 |
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)
|