My app is an order recommendation system that provides recommended quantities for different vehicle makes and models
Drop files here
or click to upload
import streamlit as st
import pandas as pd
import numpy as np
from sklearn.ensemble import RandomForestRegressor
# Initialize session state
if 'sample_data' not in st.session_state:
# Create sample historical data
np.random.seed(42)
makes = ['Toyota', 'Honda', 'Ford', 'BMW', 'Mercedes']
models = {
'Toyota': ['Camry', 'Corolla', 'RAV4'],
'Honda': ['Civic', 'Accord', 'CR-V'],
'Ford': ['F-150', 'Explorer', 'Mustang'],
'BMW': ['3 Series', '5 Series', 'X5'],
'Mercedes': ['C-Class', 'E-Class', 'GLC']
}
data = []
for make in makes:
for model in models[make]:
for month in range(1, 13):
for year in [2021, 2022, 2023]:
base_demand = np.random.randint(50, 200)
seasonal_factor = 1 + 0.2 * np.sin(2 * np.pi * month / 12)
actual_sales = int(base_demand * seasonal_factor * (1 + np.random.normal(0, 0.1)))
data.append({
'make': make,
'model': model,
'year': year,
'month': month,
'sales': actual_sales
})
st.session_state.sample_data = pd.DataFrame(data)
# Title and description
st.title('Vehicle Order Recommendation System')
st.markdown("""
This system helps predict recommended order quantities for different vehicle makes and models
based on historical sales data and seasonal patterns.
""")
# Sidebar filters
st.sidebar.header('Select Vehicle Details')
selected_make = st.sidebar.selectbox('Make', options=sorted(st.session_state.sample_data['make'].unique()))
models_for_make = sorted(st.session_state.sample_data[
st.session_state.sample_data['make'] == selected_make]['model'].unique())
selected_model = st.sidebar.selectbox('Model', options=models_for_make)
# Prepare data for the selected make/model
filtered_data = st.session_state.sample_data[
(st.session_state.sample_data['make'] == selected_make) &
(st.session_state.sample_data['model'] == selected_model)
].copy()
# Train a simple model
X = filtered_data[['year', 'month']]
y = filtered_data['sales']
model = RandomForestRegressor(n_estimators=100, random_state=42)
model.fit(X, y)
# Show historical data
st.subheader('Historical Sales Data')
st.line_chart(filtered_data.set_index(['year', 'month'])['sales'])
# Make predictions for next 6 months
last_date = pd.to_datetime(f"{filtered_data['year'].max()}-{filtered_data['month'].max()}-01")
future_dates = pd.date_range(start=last_date, periods=7, freq='M')[1:]
future_data = pd.DataFrame({
'year': future_dates.year,
'month': future_dates.month
})
predictions = model.predict(future_data)
predictions = np.round(predictions).astype(int)
# Display recommendations
st.subheader('Order Recommendations')
st.markdown(f"Recommended order quantities for **{selected_make} {selected_model}**:")
recommendations_df = pd.DataFrame({
'Year': future_dates.year,
'Month': future_dates.month,
'Recommended Quantity': predictions
})
st.table(recommendations_df)
# Additional insights
st.subheader('Additional Insights')
avg_monthly_sales = filtered_data.groupby('month')['sales'].mean().round(0)
peak_month = avg_monthly_sales.idxmax()
peak_sales = avg_monthly_sales.max()
st.markdown(f"""
- Peak sales month: {peak_month} (average of {peak_sales:.0f} units)
- Average monthly sales: {avg_monthly_sales.mean():.0f} units
- Yearly trend: {'+' if filtered_data.groupby('year')['sales'].mean().is_monotonic_increasing else '-'}
""")
# Confidence disclaimer
st.markdown("""
---
*Note: These recommendations are based on historical data and simple seasonal patterns.
Actual optimal quantities may vary based on additional factors such as market conditions,
promotions, and inventory costs.*
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?