Annikaijak
commited on
Commit
•
dc1b38b
1
Parent(s):
4ec0bec
Update app.py
Browse files
app.py
CHANGED
@@ -62,7 +62,8 @@ with tab1:
|
|
62 |
|
63 |
# Retrieving building data
|
64 |
building_new = retrieve_building()
|
65 |
-
|
|
|
66 |
building_most_recent_prediction = building_new[['x', 'y', 'z']]
|
67 |
building_most_recent_prediction = building_hist_model.predict(building_most_recent_prediction)
|
68 |
building_new['Status'] = building_most_recent_prediction
|
@@ -98,7 +99,7 @@ with tab1:
|
|
98 |
# Retrieving building data
|
99 |
bikelane_new = retrieve_bikelane()
|
100 |
|
101 |
-
|
102 |
bikelane_most_recent_prediction = bikelane_new[['x', 'y', 'z']]
|
103 |
bikelane_most_recent_prediction = bikelane_hist_model.predict(bikelane_most_recent_prediction)
|
104 |
bikelane_new['Status'] = bikelane_most_recent_prediction
|
@@ -107,6 +108,7 @@ with tab1:
|
|
107 |
bikelane_new = bikelane_new.set_index(['Time'])
|
108 |
st.dataframe(bikelane_new[['Status']].tail(5))
|
109 |
|
|
|
110 |
if st.button("Update application"):
|
111 |
# Clear cached data
|
112 |
st.cache_data.clear()
|
@@ -114,6 +116,7 @@ with tab1:
|
|
114 |
st.experimental_rerun()
|
115 |
|
116 |
with tab2:
|
|
|
117 |
def explore_magnetic_field(model, x, y, z):
|
118 |
input_list = [x, y, z]
|
119 |
res = model.predict(np.asarray(input_list).reshape(1,-1))
|
@@ -123,23 +126,27 @@ with tab2:
|
|
123 |
else:
|
124 |
label = "No vehicle detected"
|
125 |
return label
|
126 |
-
|
|
|
127 |
st.subheader('Experiment with building model:')
|
128 |
x_input_building = st.slider("Choose your x-value", -232, 909, 0)
|
129 |
y_input_building = st.slider("Choose your y-value", -1112, 435, 0)
|
130 |
z_input_building = st.slider("Choose your z-value", -1648, 226, 0)
|
131 |
|
|
|
132 |
if st.button("Predict building input"):
|
133 |
building_input_prediction = explore_magnetic_field(building_hist_model, x_input_building, y_input_building, z_input_building)
|
134 |
st.write(building_input_prediction)
|
135 |
|
136 |
st.divider()
|
137 |
|
|
|
138 |
st.subheader('Experiment with bikelane model:')
|
139 |
x_input_bikelane = st.slider("Choose your x-value", -547, 288, 0)
|
140 |
y_input_bikelane = st.slider("Choose your y-value", -1007, 786, 0)
|
141 |
z_input_bikelane = st.slider("Choose your z-value", -1475, 16, 0)
|
142 |
|
|
|
143 |
if st.button("Predict bikelane input"):
|
144 |
bikelane_input_prediction = explore_magnetic_field(bikelane_hist_model, x_input_bikelane, y_input_bikelane, z_input_bikelane)
|
145 |
st.write(bikelane_input_prediction)
|
@@ -147,11 +154,12 @@ with tab2:
|
|
147 |
with tab3:
|
148 |
st.subheader('About the application:')
|
149 |
st.markdown('This application is made as part of the module "Data Engineering and Machine Learning Operations in Business - F2024" in Business Data Science 2nd Semester at Aalborg University Business School.')
|
150 |
-
st.markdown('The application is made by Annika and Mikkel and is divided into
|
151 |
-
st.markdown('* **Parking lot status:** The first tab includes the actual interface, where the goal has been to make a simple UI which shows if
|
152 |
-
st.markdown('* **
|
153 |
-
st.markdown('* **
|
154 |
-
st.markdown('* **
|
|
|
155 |
|
156 |
with tab4:
|
157 |
st.markdown('...')
|
@@ -173,9 +181,22 @@ with tab4:
|
|
173 |
# Display dataset overview
|
174 |
#st.subheader("Dataset Overview")
|
175 |
#st.dataframe(batch_data.head())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
|
177 |
with tab5:
|
178 |
|
|
|
179 |
st.subheader('Model to predict parking place near building:')
|
180 |
st.markdown('The predictions for the parking place near the building are made on the basis of a KNearestNeighbours model')
|
181 |
st.write(building_hist_model)
|
@@ -185,30 +206,15 @@ with tab5:
|
|
185 |
|
186 |
st.divider()
|
187 |
|
|
|
188 |
st.subheader('Model to predict parking place near bikelane:')
|
189 |
st.markdown('Just like with the other model, the predictions for the parking place near the bikelane are made on the basis of a KNearestNeighbours model')
|
190 |
st.write(bikelane_hist_model)
|
191 |
st.markdown('The accuracy if the building model is 99%')
|
192 |
st.write('**Confusion matrix:**')
|
193 |
st.image('bikelane_hist_confusion_matrix.png', caption='Confusion matrix for bikelane model')
|
194 |
-
|
195 |
-
# Not used code
|
196 |
-
|
197 |
-
# Making a countplot of the predictions
|
198 |
-
#predictions = model.predict(batch_data)
|
199 |
-
#df_test = batch_data.copy()
|
200 |
-
#df_test['predictions'] = predictions
|
201 |
-
#st.dataframe(df_test.head())
|
202 |
|
203 |
-
#plt.figure(figsize=(10, 6))
|
204 |
-
#sns.set_style("darkgrid")
|
205 |
-
#sns.countplot(data=df_test, x="predictions")
|
206 |
-
#plt.title('Distribution of Predictions')
|
207 |
-
#st.pyplot(plt)
|
208 |
|
209 |
-
#def color_prediction(val):
|
210 |
-
#color = 'red' if val=='detection' else 'green' if val=='no_detection' else 'yellow'
|
211 |
-
#return f'background-color: {color}'
|
212 |
|
213 |
# Loading the feature view with latest data for bikelane
|
214 |
#bikelane_new_fv = fs.get_feature_view(
|
@@ -230,21 +236,3 @@ with tab5:
|
|
230 |
#bikelane_new['prediction'] = bikelane_most_recent_prediction
|
231 |
#bikelane_new = bikelane_new.set_index(['time'])
|
232 |
#st.dataframe(bikelane_new[['prediction']].tail(5).style.applymap(color_prediction, subset=['prediction']))
|
233 |
-
|
234 |
-
|
235 |
-
#if st.button("Update application"):
|
236 |
-
#st.rerun()
|
237 |
-
# values cannot be used in st.session_state!!
|
238 |
-
#if 'my_values' not in st.session_state:
|
239 |
-
#st.session_state.my_values = list()
|
240 |
-
|
241 |
-
#if not st.session_state.my_values:
|
242 |
-
#st.session_state.my_values.append(0)
|
243 |
-
|
244 |
-
#new_value = st.session_state.my_values[-1] + random.randrange(-100, 100) / 100
|
245 |
-
|
246 |
-
#st.session_state.my_values.append(new_value)
|
247 |
-
|
248 |
-
#time.sleep(.2)
|
249 |
-
|
250 |
-
#st.experimental_rerun()
|
|
|
62 |
|
63 |
# Retrieving building data
|
64 |
building_new = retrieve_building()
|
65 |
+
|
66 |
+
# Making the predictions and getting the latest data
|
67 |
building_most_recent_prediction = building_new[['x', 'y', 'z']]
|
68 |
building_most_recent_prediction = building_hist_model.predict(building_most_recent_prediction)
|
69 |
building_new['Status'] = building_most_recent_prediction
|
|
|
99 |
# Retrieving building data
|
100 |
bikelane_new = retrieve_bikelane()
|
101 |
|
102 |
+
# Making the predictions and getting the latest data
|
103 |
bikelane_most_recent_prediction = bikelane_new[['x', 'y', 'z']]
|
104 |
bikelane_most_recent_prediction = bikelane_hist_model.predict(bikelane_most_recent_prediction)
|
105 |
bikelane_new['Status'] = bikelane_most_recent_prediction
|
|
|
108 |
bikelane_new = bikelane_new.set_index(['Time'])
|
109 |
st.dataframe(bikelane_new[['Status']].tail(5))
|
110 |
|
111 |
+
# Update button
|
112 |
if st.button("Update application"):
|
113 |
# Clear cached data
|
114 |
st.cache_data.clear()
|
|
|
116 |
st.experimental_rerun()
|
117 |
|
118 |
with tab2:
|
119 |
+
# Defining a prediction function
|
120 |
def explore_magnetic_field(model, x, y, z):
|
121 |
input_list = [x, y, z]
|
122 |
res = model.predict(np.asarray(input_list).reshape(1,-1))
|
|
|
126 |
else:
|
127 |
label = "No vehicle detected"
|
128 |
return label
|
129 |
+
|
130 |
+
# Creating sliders for building model
|
131 |
st.subheader('Experiment with building model:')
|
132 |
x_input_building = st.slider("Choose your x-value", -232, 909, 0)
|
133 |
y_input_building = st.slider("Choose your y-value", -1112, 435, 0)
|
134 |
z_input_building = st.slider("Choose your z-value", -1648, 226, 0)
|
135 |
|
136 |
+
# Making a prediction button for building model
|
137 |
if st.button("Predict building input"):
|
138 |
building_input_prediction = explore_magnetic_field(building_hist_model, x_input_building, y_input_building, z_input_building)
|
139 |
st.write(building_input_prediction)
|
140 |
|
141 |
st.divider()
|
142 |
|
143 |
+
# Creating sliders for bikelane model
|
144 |
st.subheader('Experiment with bikelane model:')
|
145 |
x_input_bikelane = st.slider("Choose your x-value", -547, 288, 0)
|
146 |
y_input_bikelane = st.slider("Choose your y-value", -1007, 786, 0)
|
147 |
z_input_bikelane = st.slider("Choose your z-value", -1475, 16, 0)
|
148 |
|
149 |
+
# Making a prediction button for bikelane model
|
150 |
if st.button("Predict bikelane input"):
|
151 |
bikelane_input_prediction = explore_magnetic_field(bikelane_hist_model, x_input_bikelane, y_input_bikelane, z_input_bikelane)
|
152 |
st.write(bikelane_input_prediction)
|
|
|
154 |
with tab3:
|
155 |
st.subheader('About the application:')
|
156 |
st.markdown('This application is made as part of the module "Data Engineering and Machine Learning Operations in Business - F2024" in Business Data Science 2nd Semester at Aalborg University Business School.')
|
157 |
+
st.markdown('The application is made by Annika and Mikkel and is divided into 5 tabs:')
|
158 |
+
st.markdown('* **Parking lot status:** The first tab includes the actual interface, where the goal has been to make a simple UI which shows if 2 parking spaces are occupied or available.')
|
159 |
+
st.markdown('* **Magnetic Field Explorer:** The second tabs is made for exploring the models, where the user can test different values for x, y and z and get a prediction')
|
160 |
+
st.markdown('* **About:** In the third tab (the current tab) you can get some information about the interface.')
|
161 |
+
st.markdown('* **Dataset and visualisations:** The fourth tab contains an overview of the training data and also includes EDAs for each individual parking space. The goal with these EDAs is to give you some information about when the parking spaces usually are occupied.')
|
162 |
+
st.markdown('* **Model Performance:** The fifth tab explains how the underlying Machine Learning Model performs and how the predictor works.')
|
163 |
|
164 |
with tab4:
|
165 |
st.markdown('...')
|
|
|
181 |
# Display dataset overview
|
182 |
#st.subheader("Dataset Overview")
|
183 |
#st.dataframe(batch_data.head())
|
184 |
+
|
185 |
+
# Making a countplot of the predictions
|
186 |
+
#predictions = model.predict(batch_data)
|
187 |
+
#df_test = batch_data.copy()
|
188 |
+
#df_test['predictions'] = predictions
|
189 |
+
#st.dataframe(df_test.head())
|
190 |
+
|
191 |
+
#plt.figure(figsize=(10, 6))
|
192 |
+
#sns.set_style("darkgrid")
|
193 |
+
#sns.countplot(data=df_test, x="predictions")
|
194 |
+
#plt.title('Distribution of Predictions')
|
195 |
+
#st.pyplot(plt)
|
196 |
|
197 |
with tab5:
|
198 |
|
199 |
+
# Model performance of building model
|
200 |
st.subheader('Model to predict parking place near building:')
|
201 |
st.markdown('The predictions for the parking place near the building are made on the basis of a KNearestNeighbours model')
|
202 |
st.write(building_hist_model)
|
|
|
206 |
|
207 |
st.divider()
|
208 |
|
209 |
+
# Model performance of bikelane model
|
210 |
st.subheader('Model to predict parking place near bikelane:')
|
211 |
st.markdown('Just like with the other model, the predictions for the parking place near the bikelane are made on the basis of a KNearestNeighbours model')
|
212 |
st.write(bikelane_hist_model)
|
213 |
st.markdown('The accuracy if the building model is 99%')
|
214 |
st.write('**Confusion matrix:**')
|
215 |
st.image('bikelane_hist_confusion_matrix.png', caption='Confusion matrix for bikelane model')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
|
|
|
|
|
|
|
|
|
|
|
217 |
|
|
|
|
|
|
|
218 |
|
219 |
# Loading the feature view with latest data for bikelane
|
220 |
#bikelane_new_fv = fs.get_feature_view(
|
|
|
236 |
#bikelane_new['prediction'] = bikelane_most_recent_prediction
|
237 |
#bikelane_new = bikelane_new.set_index(['time'])
|
238 |
#st.dataframe(bikelane_new[['prediction']].tail(5).style.applymap(color_prediction, subset=['prediction']))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|