Spaces:
Sleeping
Sleeping
fschwartzer
commited on
Commit
•
8a967e1
1
Parent(s):
5a6ef59
Update app.py
Browse files
app.py
CHANGED
@@ -202,7 +202,10 @@ predicted_target = knn_predict(filtered_data, 'target_column', ['latitude', 'lon
|
|
202 |
filtered_data['Predicted_target'] = predicted_target
|
203 |
|
204 |
|
205 |
-
|
|
|
|
|
|
|
206 |
# Define a PyDeck view state for the initial map view
|
207 |
view_state = pdk.ViewState(latitude=filtered_data['latitude'].mean(), longitude=filtered_data['longitude'].mean(), zoom=zoom_level)
|
208 |
|
@@ -221,6 +224,8 @@ with st.container():
|
|
221 |
# Display the map in Streamlit
|
222 |
st.pydeck_chart(deck_map)
|
223 |
#st.map(filtered_data, zoom=zoom_level, use_container_width=True)
|
|
|
|
|
224 |
st.write("Dados:", filtered_data) # Debug: Print filtered_data
|
225 |
|
226 |
if st.button('Baixar planilha'):
|
@@ -247,7 +252,7 @@ with st.container():
|
|
247 |
download_placeholder = st.empty()
|
248 |
download_placeholder.markdown(href, unsafe_allow_html=True)
|
249 |
|
250 |
-
|
251 |
folium_layermap = folium.Map(location=[custom_lat, custom_lon], tiles="Cartodb Positron", zoom_start=14)
|
252 |
|
253 |
# Add heatmap layers for 'Valor_Urb', 'Valor_Eqp', and 'RENDA'
|
@@ -261,39 +266,40 @@ with st.container():
|
|
261 |
# Display the map using st_folium
|
262 |
st_folium(folium_layermap, width=1200, height=400)
|
263 |
|
264 |
-
|
|
|
265 |
|
266 |
-
# Function to perform bootstrap on the predicted target values
|
267 |
-
def bootstrap_stats(bound_data, num_samples=1000):
|
268 |
-
|
269 |
-
|
270 |
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
|
281 |
-
|
282 |
|
283 |
-
# Apply KNN and get predicted Predicted_target values
|
284 |
-
predicted_target = knn_predict(filtered_data, 'Predicted_target', ['latitude', 'longitude', 'area_feature'])
|
285 |
|
286 |
-
# Check if there are predictions to display
|
287 |
-
if 'Predicted_target' in filtered_data.columns and not np.all(predicted_target == 0):
|
288 |
|
289 |
-
|
290 |
-
|
291 |
|
292 |
-
|
293 |
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
else:
|
299 |
-
|
|
|
202 |
filtered_data['Predicted_target'] = predicted_target
|
203 |
|
204 |
|
205 |
+
# Set custom width for columns
|
206 |
+
tab1, tab2, tab3, tab4 = st.tabs(["Mapa", "Planilha", "Variáveis", "Inteligência Artificial"])
|
207 |
+
|
208 |
+
with tab1:
|
209 |
# Define a PyDeck view state for the initial map view
|
210 |
view_state = pdk.ViewState(latitude=filtered_data['latitude'].mean(), longitude=filtered_data['longitude'].mean(), zoom=zoom_level)
|
211 |
|
|
|
224 |
# Display the map in Streamlit
|
225 |
st.pydeck_chart(deck_map)
|
226 |
#st.map(filtered_data, zoom=zoom_level, use_container_width=True)
|
227 |
+
|
228 |
+
with tab2:
|
229 |
st.write("Dados:", filtered_data) # Debug: Print filtered_data
|
230 |
|
231 |
if st.button('Baixar planilha'):
|
|
|
252 |
download_placeholder = st.empty()
|
253 |
download_placeholder.markdown(href, unsafe_allow_html=True)
|
254 |
|
255 |
+
with tab3:
|
256 |
folium_layermap = folium.Map(location=[custom_lat, custom_lon], tiles="Cartodb Positron", zoom_start=14)
|
257 |
|
258 |
# Add heatmap layers for 'Valor_Urb', 'Valor_Eqp', and 'RENDA'
|
|
|
266 |
# Display the map using st_folium
|
267 |
st_folium(folium_layermap, width=1200, height=400)
|
268 |
|
269 |
+
with tab4:
|
270 |
+
k_threshold = 5
|
271 |
|
272 |
+
# Function to perform bootstrap on the predicted target values
|
273 |
+
def bootstrap_stats(bound_data, num_samples=1000):
|
274 |
+
# Reshape the predicted_target array
|
275 |
+
bound_data = np.array(bound_data).reshape(-1, 1)
|
276 |
|
277 |
+
# Bootstrap resampling
|
278 |
+
bootstrapped_means = []
|
279 |
+
for _ in range(num_samples):
|
280 |
+
bootstrap_sample = np.random.choice(bound_data.flatten(), len(bound_data), replace=True)
|
281 |
+
bootstrapped_means.append(np.mean(bootstrap_sample))
|
282 |
|
283 |
+
# Calculate lower and higher bounds
|
284 |
+
lower_bound = np.percentile(bootstrapped_means, 16.)
|
285 |
+
higher_bound = np.percentile(bootstrapped_means, 84.)
|
286 |
|
287 |
+
return lower_bound, higher_bound
|
288 |
|
289 |
+
# Apply KNN and get predicted Predicted_target values
|
290 |
+
predicted_target = knn_predict(filtered_data, 'Predicted_target', ['latitude', 'longitude', 'area_feature'])
|
291 |
|
292 |
+
# Check if there are predictions to display
|
293 |
+
if 'Predicted_target' in filtered_data.columns and not np.all(predicted_target == 0):
|
294 |
|
295 |
+
# Apply bootstrap - bounds
|
296 |
+
lower_bound, higher_bound = bootstrap_stats(filtered_data['target_column'])
|
297 |
|
298 |
+
mean_value = np.mean(filtered_data['Predicted_target'])
|
299 |
|
300 |
+
# Display the results with custom styling
|
301 |
+
st.markdown("## **Algoritmo KNN (K-nearest neighbors)**")
|
302 |
+
st.write(f"Valor médio (Reais/m²) para as características selecionadas: ${mean_value:.2f}$ Reais")
|
303 |
+
st.write(f"Os valores podem variar entre ${lower_bound:.2f}$ e ${higher_bound:.2f}$ Reais, dependendo das características dos imóveis.")
|
304 |
+
else:
|
305 |
+
st.warning(f"**Dados insuficientes para inferência do valor. Mínimo necessário:** {k_threshold}")
|