File size: 4,518 Bytes
af80abc
 
 
 
 
 
 
 
 
 
 
9c075fc
af80abc
9c075fc
af80abc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f54e8f9
af80abc
 
 
 
 
 
 
 
 
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import streamlit as st
import joblib 
import pickle
import pandas as pd

# Load the model from disk
model = joblib.load('rf.sav')
# Load the model from disk
with open('scaler.pkl', 'rb') as file:
    scaler = pickle.load(file)

st.title('Rossmann Sales Prediction App')

st.write('This app takes in the several input parameters and predict the sales for a particular day of a 1115 rossmann stores.')


store = int(st.number_input('Store Number (select between 1-1115)', step=1, min_value=1, max_value=1115))
# st.write('Store Number is', store)

week_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
week_days_mapping = {'Monday':1, 'Tuesday':2, 'Wednesday':3, 'Thursday':4, 'Friday':5, 'Saturday':6, 'Sunday':7}

week_days_input = st.selectbox('Select the day of the week', week_days)

# st.write(week_days_input)

col1, col2 = st.columns(2)


with col1:
    promo = ['yes', 'no']
    promo_map = {'yes':1, 'no':0}

    promo_or_not = st.selectbox('Promotion was opted or not?', promo)

with col2:
    school_holiday = ['yes', 'no']
    school_map = {'yes':1, 'no':0}

    school_holiday_or_not = st.selectbox('Is there a School Holiday?', school_holiday)


col3, col4 = st.columns(2)

with col3:
    year = st.number_input('Enter the year:',step=1, min_value=1973, max_value=2025)
    

with col4:
    months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']

    month_map = {'January': 1, 'February': 2, 'March': 3, 'April': 4, 'May': 5, 'June': 6,
              'July': 7, 'August': 8, 'September': 9, 'October': 10, 'November': 11, 'December': 12}


    select_month = st.selectbox('Select the month', months)


days = st.number_input('Enter the day number for which you want to predict:', step=1, min_value=1, max_value=31)


stores_type = ['a', 'b', 'c', 'd']
stores_type_input = st.selectbox('Select the type of store', stores_type)

assortment_type = ['basic', 'extra', 'extended']
assortment_type_map = {'basic':'a', 'extra':'b', 'extended':'c'}
assortment_type_input = st.selectbox('Select the assortment type (variations in the product)', assortment_type)

customers = st.number_input('Enter the expected number of customers', step=5, min_value=5, max_value=7500)
comp_distance = st.number_input('Enter the distance in meters to the nearest competitor store', step=1)
comp_open_since_month = float(st.number_input('The month is which the nearest competitor store was opened (1-12)', step=1, min_value=1, max_value=12))
comp_open_since_year = float(st.number_input('The year in which the nearest competitor store was opened', step=1, min_value=1973, max_value=2025))


competition_open = (12* (year-comp_open_since_year)) + (month_map[select_month] - (comp_open_since_month))

if stores_type_input == 'a':
    store_type_value_b = 0
    store_type_value_c = 0
    store_type_value_d = 0

if stores_type_input == 'b':
    store_type_value_b = 1
    store_type_value_c = 0
    store_type_value_d = 0

if stores_type_input == 'c':
    store_type_value_b = 0
    store_type_value_c = 1
    store_type_value_d = 0

if stores_type_input == 'd':
    store_type_value_b = 0
    store_type_value_c = 0
    store_type_value_d = 1

if assortment_type_input == 'basic':
    assortment_b = 0
    assortment_c = 0

if assortment_type_input == 'extra':
    assortment_b = 1
    assortment_c = 0

if assortment_type_input == 'extended':
    assortment_b = 0
    assortment_c = 1





if st.button('Predict Sales'):

    try:
        final_dict = {'Store':store, 'day_of_week':week_days_mapping[week_days_input], 
                    'promotion':promo_map[promo_or_not], 'school holiday':school_map[school_holiday_or_not],
                    'year':year, 'month':month_map[select_month], 'day':days, 'store b':store_type_value_b,
                    'store c':store_type_value_c, 'store d':store_type_value_d, 'assortment b':assortment_b,
                    'assortment c':assortment_c, 'customers':customers, 'Comp Dist':comp_distance,
                    'Comp_open': competition_open}


        final_df = pd.DataFrame([final_dict])
        final_df_scaled = scaler.transform(final_df)
        # st.write(final_df_scaled)
        # st.write(final_df)

        sales = model.predict(final_df_scaled)
        st.write('The sales for this particular day of the store you selected is:', sales[0])

    except Exception as e:
        st.error('There is something wrong, please enter the correct inputs', e)