Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pickle | |
| import numpy as np | |
| import pandas as pd | |
| #from sklearn.impute import SimpleImputer | |
| #from xgboost import XGBRegressor | |
| #from sklearn.preprocessing import LabelEncoder | |
| #from sklearn.preprocessing import StandardScaler | |
| import joblib | |
| # Load the final model | |
| regressor = joblib.load("Best_model.joblib") | |
| #@st.cache_resource() | |
| def show_predict_page(): | |
| # Add a title and subtitle | |
| st.write("<center><h1>Predicting Sales App</h1></center>", unsafe_allow_html=True) | |
| # Add a subtitle or description | |
| 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!") | |
| st.subheader("Enter the following details to predict sales") | |
| input_data = { | |
| 'store_nbr': st.slider("store_nbr", step=1, min_value=0, max_value=54), | |
| 'onpromotion': st.number_input("onpromotion, 0 - 800", min_value=0, max_value=800), | |
| 'transactions': st.number_input("Number of Transactions, 0 - 10000", min_value=0, max_value=10000), | |
| 'oil_price': st.number_input("oil_price, 1 - 200", step=1, min_value=0, max_value=200), | |
| 'cluster': st.slider("cluster", step=1, min_value=0, max_value=17), | |
| 'day': st.slider("day", 1, 31, 1), | |
| 'year': st.selectbox("year", [1970]), | |
| 'month': st.slider("month", 1, 12, 1), | |
| #'dayofmonth': st.slider("dayofmonth", 1, 31, 1), | |
| #'dayofweek': st.slider("dayofweek, 0=Sun and 6=Sat", step=1, min_value=1, max_value=6), | |
| 'family': st.selectbox("products", ['AUTOMOTIVE', 'Personal Care', 'Beverages', 'STATIONERY', 'Food', 'CLEANING', 'HARDWARE', 'Home and Kitchen', 'Clothing', 'PET SUPPLIES', 'ELECTRONICS']), | |
| 'holiday_type': st.selectbox("holiday_type", ['Workday', 'holiday']), | |
| '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']) | |
| } | |
| # Create a button to make a prediction | |
| if st.button("Predict", key="predict_button", help="Click to make a prediction."): | |
| # Convert the input data to a pandas DataFrame | |
| input_df = pd.DataFrame([input_data]) | |
| # Make a prediction | |
| prediction = round(regressor.predict(input_df)[0], 2) | |
| # Display the prediction | |
| #st.write(f"The predicted sales are: {prediction}.") | |
| # Display the prediction | |
| st.subheader("Sales Prediction") | |
| st.write("The predicted sales for the company is:", prediction) |