File size: 3,480 Bytes
0d6557c
e8f77f9
85d1b9f
5fc7f38
bec82b2
 
bb4dd01
e8f77f9
e3caa07
 
42c27bc
e3caa07
 
 
e8f77f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2d202f7
 
 
 
 
 
 
 
 
 
5264b94
 
8376c96
 
 
b7be1e7
 
88a72d6
b7be1e7
 
88a72d6
 
 
 
b7be1e7
 
dc38de7
5b621df
 
bf38d13
5b621df
 
 
dc38de7
b7be1e7
dc38de7
5264b94
8376c96
dca4b08
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
import streamlit as st
import pandas as pd
from datetime import datetime
import joblib
from sklearn.base import BaseEstimator, TransformerMixin
from datetime import datetime
from transformers import SugarContentReplacer,StoreAgeCalculator  # Import the custom transformer

# Load the trained model
def load_model():
    return joblib.load("src/SuperKart_sales_prediction_model_v1_0.joblib")

model = load_model()

# Streamlit UI for Customer Churn Prediction
st.title("Sales Prediction App")
st.write("This tool predicts customer Sales details. Enter the required information below.")

# Input fields for product and store data based on SuperKart dataset features
product_weight = st.number_input("Product Weight", min_value=0.0, value=12.66)
product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, value=0.027)
product_type = st.selectbox("Product Type", ['Baking Goods', 'Breads', 'Breakfast', 'Canned', 'Dairy', 'Frozen Foods', 'Fruits and Vegetables', 'Hard Drinks', 'Health and Hygiene', 'Household', 'Meat', 'Others', 'Seafood', 'Snack Foods', 'Soft Drinks', 'Starchy Foods'])
product_mrp = st.number_input("Product MRP", min_value=0.0, value=117.08)
store_id = st.selectbox("Store ID", ['OUT001', 'OUT002', 'OUT003', 'OUT004'])
store_establishment_year = st.number_input("Store Establishment Year", min_value=1985, max_value=datetime.now().year, value=2009)
store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
store_type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type1", "Supermarket Type2", "Food Mart"])

# Convert categorical inputs to match model training
input_data = {
    'Product_Weight': [product_weight],
    'Product_Sugar_Content': [product_sugar_content],
    'Product_Allocated_Area': [product_allocated_area],
    'Product_Type': [product_type],
    'Product_MRP': [product_mrp],
    'Store_Id': [store_id],
    'Store_Establishment_Year': [store_establishment_year],
    'Store_Size': [store_size],
    'Store_Location_City_Type': [store_location_city_type],
    'Store_Type': [store_type],
}

# Convert the input data to a DataFrame
input_df = pd.DataFrame(input_data)

# Custom transformer to replace 'reg' with 'Regular' in Product_Sugar_Content
class SugarContentReplacer(BaseEstimator, TransformerMixin):
    def fit(self, input_df, y=None):
        return self

    def transform(self, input_df):
        input_df = input_df.copy()
        input_df['Product_Sugar_Content'] = input_df['Product_Sugar_Content'].replace('reg', 'Regular')
        return input_df


# Convert categorical columns to category type
input_df['Product_Sugar_Content'] = input_df['Product_Sugar_Content'].astype('category')
input_df['Product_Type'] = input_df['Product_Type'].astype('category')
input_df['Store_Id'] = input_df['Store_Id'].astype('category')
input_df['Store_Size'] = input_df['Store_Size'].astype('category')
input_df['Store_Location_City_Type'] = input_df['Store_Location_City_Type'].astype('category')
input_df['Store_Type'] = input_df['Store_Type'].astype('category')


# Make predictions
if st.button("Predict"):
    predictions = model.predict(input_df)
    st.write(f"Prediction: Based on input data, Forecasted sales revenue of its outlets for the upcoming quarter **{predictions[0]}**.")