Spaces:
Sleeping
Sleeping
fschwartzer
commited on
Commit
•
5d1bc6b
1
Parent(s):
50adf46
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,33 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
4 |
-
import seaborn as sns
|
5 |
-
import matplotlib.pyplot as plt
|
6 |
from sklearn.neighbors import KNeighborsRegressor
|
7 |
from geopy.distance import geodesic
|
8 |
import googlemaps
|
9 |
from geopy.exc import GeocoderTimedOut
|
10 |
from streamlit_folium import st_folium
|
11 |
-
from streamlit_folium import folium_static
|
12 |
import folium
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# Function to calculate distance in meters between two coordinates
|
24 |
def calculate_distance(lat1, lon1, lat2, lon2):
|
@@ -246,9 +255,26 @@ predicted_target = knn_predict(filtered_data, 'target_column', ['latitude', 'lon
|
|
246 |
# Add predicted target values to filtered_data
|
247 |
filtered_data['Predicted_target'] = predicted_target
|
248 |
|
|
|
|
|
|
|
|
|
|
|
249 |
# Display the map and filtered_data
|
250 |
with st.container():
|
251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
st.write("Dados:", filtered_data) # Debug: Print filtered_data
|
253 |
|
254 |
k_threshold = 5
|
@@ -286,14 +312,4 @@ if 'Predicted_target' in filtered_data.columns and not np.all(predicted_target =
|
|
286 |
st.write(f"Valor médio (Reais/m²) para as características selecionadas: ${mean_value:.2f}$ Reais")
|
287 |
st.write(f"Os valores podem variar entre ${lower_bound:.2f}$ e ${higher_bound:.2f}$ Reais, dependendo das características dos imóveis.")
|
288 |
else:
|
289 |
-
st.warning(f"**Dados insuficientes para inferência do valor. Mínimo necessário:** {k_threshold}")
|
290 |
-
|
291 |
-
# Plot heatmaps for 'Valor_Urb', 'Valor_Eqp', and 'RENDA'
|
292 |
-
st.subheader("Mapa de Calor para 'Valor_Urb'")
|
293 |
-
plot_heatmap(filtered_data.pivot_table(index='latitude', columns='longitude', values='Valor_Urb', aggfunc='mean'), 'Valor_Urb')
|
294 |
-
|
295 |
-
st.subheader("Mapa de Calor para 'Valor_Eqp'")
|
296 |
-
plot_heatmap(filtered_data.pivot_table(index='latitude', columns='longitude', values='Valor_Eqp', aggfunc='mean'), 'Valor_Eqp')
|
297 |
-
|
298 |
-
st.subheader("Mapa de Calor para 'RENDA'")
|
299 |
-
plot_heatmap(filtered_data.pivot_table(index='latitude', columns='longitude', values='RENDA', aggfunc='mean'), 'RENDA')
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
|
|
|
|
4 |
from sklearn.neighbors import KNeighborsRegressor
|
5 |
from geopy.distance import geodesic
|
6 |
import googlemaps
|
7 |
from geopy.exc import GeocoderTimedOut
|
8 |
from streamlit_folium import st_folium
|
|
|
9 |
import folium
|
10 |
+
from branca.colormap import LinearColormap
|
11 |
+
|
12 |
+
# Function to add heatmap layer to folium map
|
13 |
+
def add_heatmap_layer(map_obj, data, column_name, colormap_name, radius=15):
|
14 |
+
heat_data = data[['latitude', 'longitude', column_name]].dropna()
|
15 |
+
heat_layer = folium.FeatureGroup(name=f'Heatmap - {column_name}')
|
16 |
+
|
17 |
+
cmap = LinearColormap(colors=['blue', 'white', 'red'], vmin=heat_data[column_name].min(), vmax=heat_data[column_name].max())
|
18 |
+
|
19 |
+
for index, row in heat_data.iterrows():
|
20 |
+
folium.CircleMarker(
|
21 |
+
location=[row['latitude'], row['longitude']],
|
22 |
+
radius=radius,
|
23 |
+
fill=True,
|
24 |
+
fill_color=cmap(row[column_name]),
|
25 |
+
fill_opacity=0.7,
|
26 |
+
color='black',
|
27 |
+
weight=0.5,
|
28 |
+
).add_to(heat_layer)
|
29 |
+
|
30 |
+
heat_layer.add_to(map_obj)
|
31 |
|
32 |
# Function to calculate distance in meters between two coordinates
|
33 |
def calculate_distance(lat1, lon1, lat2, lon2):
|
|
|
255 |
# Add predicted target values to filtered_data
|
256 |
filtered_data['Predicted_target'] = predicted_target
|
257 |
|
258 |
+
# Display the map and filtered_data
|
259 |
+
#with st.container():
|
260 |
+
#st.map(filtered_data, zoom=zoom_level, use_container_width=True)
|
261 |
+
#st.write("Dados:", filtered_data) # Debug: Print filtered_data
|
262 |
+
|
263 |
# Display the map and filtered_data
|
264 |
with st.container():
|
265 |
+
folium_map = folium.Map(location=[custom_lat, custom_lon], zoom_start=zoom_level, control_scale=True)
|
266 |
+
|
267 |
+
# Add heatmap layers for 'Valor_Urb', 'Valor_Eqp', and 'RENDA'
|
268 |
+
add_heatmap_layer(folium_map, filtered_data, 'Valor_Urb', 'RdBu_r')
|
269 |
+
add_heatmap_layer(folium_map, filtered_data, 'Valor_Eqp', 'RdBu_r')
|
270 |
+
add_heatmap_layer(folium_map, filtered_data, 'RENDA', 'RdBu_r')
|
271 |
+
|
272 |
+
# Add layer control
|
273 |
+
folium.LayerControl().add_to(folium_map)
|
274 |
+
|
275 |
+
# Display the map
|
276 |
+
folium_static(folium_map)
|
277 |
+
|
278 |
st.write("Dados:", filtered_data) # Debug: Print filtered_data
|
279 |
|
280 |
k_threshold = 5
|
|
|
312 |
st.write(f"Valor médio (Reais/m²) para as características selecionadas: ${mean_value:.2f}$ Reais")
|
313 |
st.write(f"Os valores podem variar entre ${lower_bound:.2f}$ e ${higher_bound:.2f}$ Reais, dependendo das características dos imóveis.")
|
314 |
else:
|
315 |
+
st.warning(f"**Dados insuficientes para inferência do valor. Mínimo necessário:** {k_threshold}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|