import numpy as np import pandas as pd import streamlit as st import matplotlib.pyplot as plt import seaborn as sns import warnings warnings.filterwarnings('ignore') from scipy import stats import pickle from sklearn.model_selection import train_test_split, cross_validate import optuna from sklearn.preprocessing import StandardScaler, OneHotEncoder, OrdinalEncoder from sklearn.pipeline import Pipeline from sklearn.compose import ColumnTransformer from optuna.samplers import TPESampler from optuna.visualization import plot_param_importances,plot_optimization_history from sklearn.neighbors import KNeighborsRegressor from sklearn.linear_model import LinearRegression, Ridge, Lasso, ElasticNet from sklearn.tree import DecisionTreeRegressor from sklearn.ensemble import RandomForestRegressor, BaggingRegressor, VotingRegressor from sklearn.metrics import mean_squared_error, r2_score, mean_absolute_error def load_model(): with open("regression .pkl", "rb") as f: model = pickle.load(f) return model model = load_model() st.set_page_config(page_title="Walmart Sales Predictor", page_icon="🛒", layout="centered") st.title("🛒 Walmart Sales Prediction") st.markdown(""" ### 📊 Predict Weekly Sales for Walmart Stores Just enter the store details below, and our AI model will predict the weekly sales! 💰 """) st.title("🛒 Walmart Sales Prediction") st.write("Enter the input features below to predict the weekly sales.") # Store input (float64) store = st.number_input("Enter Store ID (1-50)", min_value=1.0, max_value=50.0, step=1.0, format="%.1f") # Holiday_Flag input (object, but should be categorical) holiday_flag = st.selectbox("Is it a Holiday?", [0,1]) # Temperature input (float64) temperature = st.number_input("Enter Temperature (°C)", value=20.0, format="%.2f") # Fuel Price input (float64) fuel_price = st.number_input("Enter Fuel Price", value=3.5, format="%.3f") # CPI input (float64) cpi = st.number_input("Enter CPI", value=200.0, format="%.6f") # Unemployment input (float64) unemployment = st.number_input("Enter Unemployment Rate", value=5.0, format="%.3f") # Month input (float64) month = st.number_input("Enter Month (1-12)", min_value=1.0, max_value=12.0, step=1.0, format="%.1f") # Prediction button if st.button("Predict Sales"): #input_features = [[store, holiday_flag, temperature, fuel_price, cpi, unemployment,month]] try: prediction = model.predict([[store, holiday_flag, temperature, fuel_price, cpi, unemployment, month]]) prediction st.success(f"Predicted Weekly Sales: ${prediction[0]:,.2f}") except Exception as e: st.error(f"Error during prediction: {e}")