File size: 2,180 Bytes
6ae89f6
 
 
891dffa
6ae89f6
23809d3
 
 
 
 
 
 
 
d825269
6ae89f6
891dffa
 
6ae89f6
 
 
891dffa
 
 
 
 
 
 
6ae89f6
d825269
6ae89f6
891dffa
6ae89f6
891dffa
 
 
 
6ae89f6
891dffa
 
d825269
08df2d8
6ae89f6
08df2d8
6ae89f6
891dffa
1ae3560
08df2d8
f767b5a
6ae89f6
08df2d8
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
import pandas as pd
import streamlit as st
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']

# Define app title and description
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("**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, value=6)
    input_data['year'] = st.number_input("Year", 2018, 2020, value=2020, step=1)

# Create a button to make a prediction
if st.button("Predict"):
    # Feature Scaling
    numerical_cols = ['day', 'month', 'year', 'shop_id', 'item_id', 'item_price', 'item_category_id']
    input_df = pd.DataFrame(input_data, index=[0])[numerical_cols]
    
    # Make predictions using the trained model
    predictions = rf_model.predict(input_df)
    
    # Display the predicted sales value to the user
    st.write("The predicted sales are:", predictions[0])