slickdata commited on
Commit
7641db4
·
1 Parent(s): 2520f96

update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -109
app.py CHANGED
@@ -1,113 +1,11 @@
1
  import streamlit as st
2
- import pickle
3
- import numpy as np
4
- import pandas as pd
5
- from sklearn.impute import SimpleImputer
6
- from xgboost import XGBRegressor
7
- from sklearn.preprocessing import LabelEncoder
8
- from sklearn.preprocessing import StandardScaler
9
- import joblib
10
 
11
 
 
12
 
13
- # Load the numerical imputer
14
- #num_imputer = joblib.load("numerical_imputer.joblib")
15
-
16
- # Load the categorical imputer
17
- #cat_imputer = joblib.load("categorical_imputer.joblib")
18
-
19
- # Load the scaler
20
- #scaler = joblib.load("scaler.joblib")
21
-
22
- # Load the label encoder for 'family' feature
23
- #le_family = joblib.load("le_family.joblib")
24
-
25
- # Load the label encoder for 'holiday_type' feature
26
- #le_holiday_type = joblib.load("le_holiday_type.joblib")
27
-
28
- # Load the label encoder for 'city' feature
29
- #le_city = joblib.load("le_city.joblib")
30
-
31
- # Load the final model
32
- regressor = joblib.load("Best_model.joblib")
33
-
34
-
35
-
36
- #@st.cache_resource()
37
- def show_predict_page():
38
- # Add a title and subtitle
39
- st.write("<center><h1>Predicting Sales App</h1></center>", unsafe_allow_html=True)
40
-
41
-
42
- # Add a subtitle or description
43
- st.write("This app predict sales by the using machine learning, based on certain input parameters. Simply enter the required information and click 'Predict' to get a sales prediction!")
44
-
45
- st.subheader("Enter the following details to predict sales")
46
-
47
- input_data = {
48
- 'store_nbr': st.slider("store_nbr", step=1, min_value=0, max_value=54),
49
- 'onpromotion': st.number_input("onpromotion, 0 - 800", min_value=0, max_value=800),
50
- 'transactions': st.number_input("Number of Transactions, 0 - 10000", min_value=0, max_value=10000),
51
- 'oil_price': st.number_input("oil_price, 1 - 200", step=1, min_value=0, max_value=200),
52
- 'cluster': st.slider("cluster", step=1, min_value=0, max_value=17),
53
- 'day': st.slider("day", 1, 31, 1),
54
- 'year': st.selectbox("year", [1970]),
55
- 'month': st.slider("month", 1, 12, 1),
56
- #'dayofmonth': st.slider("dayofmonth", 1, 31, 1),
57
- #'dayofweek': st.slider("dayofweek, 0=Sun and 6=Sat", step=1, min_value=1, max_value=6),
58
- 'family': st.selectbox("products", ['AUTOMOTIVE', 'Personal Care', 'Beverages', 'STATIONERY', 'Food', 'CLEANING', 'HARDWARE', 'Home and Kitchen', 'Clothing', 'PET SUPPLIES', 'ELECTRONICS']),
59
- 'holiday_type': st.selectbox("holiday_type", ['Workday', 'holiday']),
60
- 'city': st.selectbox("City", ['Salinas', 'Quito', 'Cayambe', 'Latacunga', 'Riobamba', 'Ibarra', 'Santo Domingo', 'Guaranda', 'Ambato', 'Guayaquil', 'Daule', 'Babahoyo', 'Quevedo', 'Playas', 'Cuenca', 'Loja', 'Machala', 'Esmeraldas', 'El Carmen', 'Libertad', 'Manta', 'Puyo'])
61
- }
62
-
63
- # Create a button to make a prediction
64
-
65
- if st.button("Predict", key="predict_button", help="Click to make a prediction."):
66
- # Convert the input data to a pandas DataFrame
67
- input_df = pd.DataFrame([input_data])
68
-
69
-
70
- # Selecting categorical and numerical columns separately
71
- # cat_columns = [col for col in input_df.columns if input_df[col].dtype == 'object']
72
- # num_columns = [col for col in input_df.columns if input_df[col].dtype != 'object']
73
-
74
-
75
- # Apply the imputers
76
- # input_df_imputed_cat = cat_imputer.transform(input_df[cat_columns])
77
- # input_df_imputed_num = num_imputer.transform(input_df[num_columns])
78
-
79
- # Convert the NumPy arrays to DataFrames
80
- # input_df_imputed_cat = pd.DataFrame(input_df_imputed_cat, columns=cat_columns)
81
- # input_df_imputed_num = pd.DataFrame(input_df_imputed_num, columns=num_columns)
82
-
83
-
84
- # Scale the numerical columns
85
- # input_df_scaled = scaler.transform(input_df_imputed_num)
86
- # input_scaled_df = pd.DataFrame(input_df_scaled , columns = num_columns)
87
-
88
- # input_df_imputed = pd.concat([input_df_imputed_cat, input_scaled_df], axis=1)
89
-
90
- # Encode the categorical columns
91
- # Encode the categorical columns
92
- # input_df_imputed['family'] = le_family.transform(input_df_imputed['family'])
93
- # input_df_imputed['holiday_type'] = le_holiday_type.transform(input_df_imputed['holiday_type'])
94
- # input_df_imputed['city'] = le_city.transform(input_df_imputed['city'])
95
-
96
-
97
- #input_encoded_df = pd.DataFrame(encoder.transform(input_df_imputed_cat))
98
- #input_encoded_df.columns = input_encoded_df.columns.astype(str)
99
-
100
-
101
- #joining the cat encoded and num scaled
102
- # final_df = input_df_imputed
103
-
104
- # Make a prediction
105
- prediction = round(regressor.predict(input_df)[0], 2)
106
-
107
-
108
- # Display the prediction
109
- #st.write(f"The predicted sales are: {prediction}.")
110
-
111
- # Display the prediction
112
- st.subheader("Sales Prediction")
113
- st.write("The predicted sales for the company is:", prediction)
 
1
  import streamlit as st
2
+ from predict_page import show_predict_page
3
+ from explore_page import show_explore_page
 
 
 
 
 
 
4
 
5
 
6
+ page = st.sidebar.selectbox("Explore Or Predict", ("Predict", "Explore"))
7
 
8
+ if page == "Predict":
9
+ show_predict_page()
10
+ else:
11
+ show_explore_page()