File size: 2,604 Bytes
6ae89f6
 
 
 
891dffa
6ae89f6
23809d3
 
 
 
 
 
 
 
6ae89f6
891dffa
 
6ae89f6
 
 
891dffa
 
 
 
 
 
 
 
6ae89f6
 
 
891dffa
6ae89f6
891dffa
 
 
 
6ae89f6
891dffa
 
 
 
6ae89f6
891dffa
6ae89f6
891dffa
 
 
 
 
 
 
 
 
 
 
 
 
 
6ae89f6
891dffa
 
 
6ae89f6
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
import pandas as pd
import streamlit as st
import numpy as np
import pickle
from sklearn.preprocessing import MinMaxScaler

# Load the scaler and model
with open('model_and_scaler.pkl', 'rb') as file:
    model_and_scaler = pickle.load(file)

# Extract the scaler and model
scaler = model_and_scaler['scaler']
rf_model = model_and_scaler['model']

st.image("https://pbs.twimg.com/media/DywhyJiXgAIUZej?format=jpg&name=medium")
st.title("Store Sales Prediction App")
st.caption("This app predicts sales patterns in different stores based on the inputs.")

# Sidebar with input field descriptions
st.sidebar.header("Description of The Required Input Fields")
st.sidebar.markdown("**Shop ID**: Unique identifier for a specific shop.")
st.sidebar.markdown("**Item ID**: Unique identifier for a product.")
st.sidebar.markdown("**Item Price**: Current price of an item.")
st.sidebar.markdown("**Item Category ID**: Unique identifier for an item category.")
st.sidebar.markdown("**Total Sales**: The total daily sales.")
st.sidebar.markdown("**Day**: Day the product was purchased.")
st.sidebar.markdown("**Month**: Month the product was purchased.")
st.sidebar.markdown("**Year**: Year the product was purchased.")

 # Create the input fields
input_data = {}
col1, col2 = st.columns(2)
with col1:
    input_data['shop_id'] = st.slider("Shop ID", 0, 54)
    input_data['item_id'] = st.slider("Item ID", 100000, 1022169)
    input_data['item_price'] = st.number_input("Item Price", 0, 153990)
    input_data['item_category_id'] = st.slider("Item Category ID", 0, 166)

with col2:
    input_data['day'] = st.slider("Day", 1, 31)
    input_data['month'] = st.slider("Month", 1, 12)
    input_data['year'] = st.number_input("Year", 2018, 2019, 2020)

# Create a button to make a prediction
if st.button("Predict"):
    # Feature Scaling
    numerical_cols = ['shop_id', 'item_id', 'item_price', 'item_category_id', 'total_sales', 'day', 'month', 'year', 'day_of_week']
    scaler = MinMaxScaler()
    input_df = pd.DataFrame(input_data, index=[0])
    input_df_scaled = scaler.fit_transform(input_df[numerical_cols])
    input_df_scaled = pd.DataFrame(input_df_scaled, columns=numerical_cols)
    
    # Load the scaler and model
    with open('model_and_scaler.pkl', 'rb') as file:
        model_and_scaler = pickle.load(file)
    
    # Extract the model
    rf_model = model_and_scaler['model']
    
    # Make predictions using the trained model
    predictions = rf_model.predict(input_df_scaled)
    
    # Display the predicted sales value to the user
    st.write("The predicted sales are:", predictions[0])