File size: 2,562 Bytes
8f460b5 1840ab8 d481617 1840ab8 d481617 1840ab8 d481617 2f5a227 1840ab8 d481617 1840ab8 d481617 1840ab8 bb3d06f 1840ab8 58f8c94 d481617 1840ab8 d481617 bb3d06f d481617 58f8c94 8950d93 1840ab8 d481617 1840ab8 778f981 1840ab8 |
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
import streamlit as st
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
# Streamlit UI
st.set_page_config(page_title="BigMart Sales Predictor", page_icon="🛒", layout="centered")
st.title("🛒 BigMart Sales Prediction using Real World Dataset")
st.markdown("Fill in the product details to get a sales prediction.")
# Load and preprocess dataset
@st.cache_data
def load_data():
data = pd.read_csv("Train.csv") # 👈 Make sure Train.csv is in the same directory
# Handle missing values
data.fillna(data.mean(numeric_only=True), inplace=True)
data.fillna("Unknown", inplace=True)
# Encode categorical columns
label_enc = LabelEncoder()
for col in ['Item_Fat_Content', 'Item_Type', 'Outlet_Identifier', 'Outlet_Size', 'Outlet_Location_Type', 'Outlet_Type']:
data[col] = label_enc.fit_transform(data[col])
return data
df = load_data()
# Select features and target
features = ['Item_Weight', 'Item_Visibility', 'Item_MRP']
target = 'Item_Outlet_Sales'
X = df[features]
y = df[target]
# Train model
model = LinearRegression()
model.fit(X, y)
# Input UI
product_name = st.text_input("📦 Product Name")
item_weight = st.number_input("⚖️ Item Weight (kg)", min_value=0.0, step=0.1)
item_visibility = st.slider("👀 Item Visibility", 0.0, 1.0, 0.05)
item_mrp = st.number_input("💰 Item MRP", min_value=0.0, step=1.0)
# Prediction
if st.button("Predict Sales"):
if not product_name:
st.warning("Please enter a product name.")
else:
user_input = np.array([[item_weight, item_visibility, item_mrp]])
predicted_sales = model.predict(user_input)[0]
st.success(f"📈 Predicted Sales for '{product_name}': ₹{predicted_sales:,.2f}")
# Optional: Download Prediction
result_df = pd.DataFrame({
"Product Name": [product_name],
"Item Weight": [item_weight],
"Item Visibility": [item_visibility],
"Item MRP": [item_mrp],
"Predicted Sales": [predicted_sales]
})
st.download_button("📥 Download Result as CSV", result_df.to_csv(index=False), file_name="prediction.csv", mime="text/csv")
# Sidebar Info
st.sidebar.title("📌 About")
st.sidebar.markdown("""
This app uses a **real BigMart dataset** from Kaggle and a **Linear Regression model** to predict sales.
You can customize features or switch to advanced ML models later!
""")
|