Spaces:
Sleeping
Sleeping
File size: 6,533 Bytes
97d7d24 6fffc1d 32b6f07 97d7d24 3c8506c 97d7d24 8fc3d1e 5ef7e2a 6fffc1d 8fc3d1e 6fffc1d 97d7d24 8fc3d1e 97d7d24 29c5c9b 3c8506c 29c5c9b 3c8506c 29c5c9b 3c8506c 29c5c9b 3c8506c 5ef7e2a d3f094e 97d7d24 8fc3d1e 97d7d24 8fc3d1e f69ec6e 29c5c9b f69ec6e 8fc3d1e 97d7d24 8fc3d1e 97d7d24 8fc3d1e 97d7d24 8fc3d1e 97d7d24 8fc3d1e 97d7d24 54578cc 358cfc6 97d7d24 8fc3d1e 02eb897 3c8506c 747ee92 d26c9f3 |
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# import required libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pickle
import joblib
import os
from datetime import datetime
from datetime import timedelta
from sklearn.model_selection import RandomizedSearchCV, GridSearchCV, train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import r2_score
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import StandardScaler
import streamlit as st
import warnings
warnings.filterwarnings('ignore')
st.title("Predict Unrolled Values")
st.sidebar.header('Enter the Details here')
st.write("""This Random Forest Regressor model helps to forecast unrolled values with impressive accuracy.
Leveraging the strength of the Random Forest technique, we can now make reliable predictions that
enable us to plan and strategize effectively in the fast-paced media landscape.""")
# load the saved model using pickle
with open('aajTak_model.pkl', 'rb') as file:
model = pickle.load(file)
# # # load the saved model using joblib
# model3 = joblib.load('aajTak_model.joblib')
# Load the saved weekDay label encoder object using pickle
with open('weekDay_le.pkl','rb') as file1:
weekDay_le = pickle.load(file1)
# Load the saved timeBand label encoder object using pickle
with open('timeBand_le.pkl','rb') as file2:
timeBand_le = pickle.load(file2)
# previous_number_of_repairs =
# st.sidebar.number_input('Enter the Previous Number of Repairs Undergone 0 to 5 )',min_value=0,max_value=5,step=1)
# DATA from user
def user_report():
# Share = round(float(st.sidebar.slider('Share', 0.000000, 100.000000, 0.611246, step=0.000001)), 6)
# AMA = round(float(st.sidebar.slider('AMA', 0.000000, 45.000000, 4.196084, step=0.000001)), 6)
# rate = round(float(st.sidebar.slider('rate', 0.000000, 1.500000, 0.018516, step=0.000001)), 6)
# daily_reach = round(float(st.sidebar.slider('daily reach', 0.000000, 300.000000, 36.23)), 6)
# cume_reach = round(float(st.sidebar.slider('cume reach', 0.000000, 300.000000, 36.231006)), 6)
Share = round(float(st.sidebar.number_input('Share', 0.0, 100.0, 0.611246, step=0.000001)), 6)
AMA = round(float(st.sidebar.number_input('AMA', 0.0, 45.0, 4.196084, step=0.000001)), 6)
rate = round(float(st.sidebar.number_input('rate', 0.0, 1.5, 0.018516, step=0.000001)), 6)
daily_reach = round(float(st.sidebar.number_input('daily reach', 0.0, 300.0, 36.23, step=0.000001)), 6)
cume_reach = round(float(st.sidebar.number_input('cume reach', 0.0, 300.0, 36.231006, step=0.000001)), 6)
# Share = st.sidebar.slider('Share', 0, 100, 0)
# AMA = st.sidebar.slider('AMA', 0, 45, 4)
# rate = st.sidebar.slider('rate', 0, 1, 0)
# daily_reach = st.sidebar.slider('daily reach', 0, 300, 36)
# cume_reach = st.sidebar.slider('cume reach', 0, 300, 36)
# Output: {'Friday': 0, 'Monday': 1, 'Saturday': 2, 'Sunday': 3, 'Thursday': 4, 'Tuesday': 5, 'Wednesday': 6}
Week_Day_Encoded = st.sidebar.selectbox("Week Day",
("Monday", "Tuesday","Wednesday","Thursday","Friday", "Saturday", "Sunday" ))
if Week_Day_Encoded=='Monday':
Week_Day_Encoded=1
elif Week_Day_Encoded=="Tuesday":
Week_Day_Encoded=5
elif Week_Day_Encoded=="Wednesday":
Week_Day_Encoded=6
elif Week_Day_Encoded=="Thursday":
Week_Day_Encoded =4
elif Week_Day_Encoded=="Friday":
Week_Day_Encoded =0
elif Week_Day_Encoded=="Saturday":
Week_Day_Encoded =2
else:
Week_Day_Encoded=3
# The Time Band dictionary provided
time_band_dict = {
'02:00:00 - 02:30:00': 0, '02:30:00 - 03:00:00': 1, '03:00:00 - 03:30:00': 2, '03:30:00 - 04:00:00': 3,
'04:00:00 - 04:30:00': 4, '04:30:00 - 05:00:00': 5, '05:00:00 - 05:30:00': 6, '05:30:00 - 06:00:00': 7,
'06:00:00 - 06:30:00': 8, '06:30:00 - 07:00:00': 9, '07:00:00 - 07:30:00': 10, '07:30:00 - 08:00:00': 11,
'08:00:00 - 08:30:00': 12, '08:30:00 - 09:00:00': 13, '09:00:00 - 09:30:00': 14, '09:30:00 - 10:00:00': 15,
'10:00:00 - 10:30:00': 16, '10:30:00 - 11:00:00': 17, '11:00:00 - 11:30:00': 18, '11:30:00 - 12:00:00': 19,
'12:00:00 - 12:30:00': 20, '12:30:00 - 13:00:00': 21, '13:00:00 - 13:30:00': 22, '13:30:00 - 14:00:00': 23,
'14:00:00 - 14:30:00': 24, '14:30:00 - 15:00:00': 25, '15:00:00 - 15:30:00': 26, '15:30:00 - 16:00:00': 27,
'16:00:00 - 16:30:00': 28, '16:30:00 - 17:00:00': 29, '17:00:00 - 17:30:00': 30, '17:30:00 - 18:00:00': 31,
'18:00:00 - 18:30:00': 32, '18:30:00 - 19:00:00': 33, '19:00:00 - 19:30:00': 34, '19:30:00 - 20:00:00': 35,
'20:00:00 - 20:30:00': 36, '20:30:00 - 21:00:00': 37, '21:00:00 - 21:30:00': 38, '21:30:00 - 22:00:00': 39,
'22:00:00 - 22:30:00': 40, '22:30:00 - 23:00:00': 41, '23:00:00 - 23:30:00': 42, '23:30:00 - 24:00:00': 43,
'24:00:00 - 24:30:00': 44, '24:30:00 - 25:00:00': 45, '25:00:00 - 25:30:00': 46, '25:30:00 - 26:00:00': 47}
selected_time_band = st.sidebar.selectbox('Time Band', list(time_band_dict.keys()))
Time_Band_Encoded = time_band_dict[selected_time_band]
user_report_data = {
'Share': Share,
'AMA': AMA,
'rate': rate,
'daily reach': daily_reach,
'cume reach': cume_reach,
'Week_Day_Encoded': Week_Day_Encoded,
'Time_Band_Encoded': Time_Band_Encoded}
report_data = pd.DataFrame(user_report_data, index=[0])
return report_data
#Customer Data
user_data = user_report()
st.subheader("Entered Details")
st.write(user_data)
# define the prediction function
def predict_unrolled_value(user_data):
# make the prediction using the loaded model and input data
predicted_unrolled_value = model.predict(user_data)
# # return the predict_unrolled_value as output
# return predicted_unrolled_value[0]
# return the predicted unrolled value as output with 6 decimal places
return float(predicted_unrolled_value[0])
# Function calling
y_pred = predict_unrolled_value(user_data)
# CSS code for changing color of the button
st.markdown("""
<style>
.stButton button {
background-color: #668f45;
color: white;
}
</style>
""", unsafe_allow_html=True)
# st.write("Click here to see the Predictions")
if st.button("Click here for Predictions"):
st.subheader(f"Predicted Unrolled Value: {y_pred:.6f}")
# Testing purpose
# 0.611246 4.196084 0.018516 36.23 36.231006 'Saturday' ''08:00:00 - 08:30:00''
# 3.711884
|