Spaces:
Sleeping
Sleeping
fschwartzer
commited on
Commit
•
02052b7
1
Parent(s):
84248e4
Update app.py
Browse files
app.py
CHANGED
@@ -229,8 +229,28 @@ with st.container():
|
|
229 |
|
230 |
k_threshold = 5
|
231 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
# Apply KNN and get predicted Predicted_target values
|
233 |
-
predicted_target = knn_predict(filtered_data, 'Predicted_target', ['latitude', 'longitude', 'area_feature'])
|
234 |
|
235 |
# Check if there are predictions to display
|
236 |
if 'Predicted_target' in filtered_data.columns and not np.all(predicted_target == 0):
|
@@ -240,5 +260,13 @@ if 'Predicted_target' in filtered_data.columns and not np.all(predicted_target =
|
|
240 |
# Display the predicted Predicted_target values
|
241 |
st.write("Valores (R$/m²) previstos com algoritmo KNN:")
|
242 |
st.write(filtered_data[['Localização', 'Atotal', 'Apriv', 'Vunit_total', 'Vunit_priv', 'Predicted_target']])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
else:
|
244 |
st.warning(f"Dados insuficientes para inferência do valor. Mínimo necessário: {k_threshold}")
|
|
|
229 |
|
230 |
k_threshold = 5
|
231 |
|
232 |
+
# Function to perform bootstrap on the predicted target values
|
233 |
+
def bootstrap_stats(predicted_target, num_samples=1000):
|
234 |
+
# Reshape the predicted_target array
|
235 |
+
predicted_target = np.array(predicted_target).reshape(-1, 1)
|
236 |
+
|
237 |
+
# Bootstrap resampling
|
238 |
+
bootstrapped_means = []
|
239 |
+
for _ in range(num_samples):
|
240 |
+
bootstrap_sample = np.random.choice(predicted_target.flatten(), len(predicted_target), replace=True)
|
241 |
+
bootstrapped_means.append(np.mean(bootstrap_sample))
|
242 |
+
|
243 |
+
# Calculate lower and higher bounds
|
244 |
+
lower_bound = np.percentile(bootstrapped_means, 2.5)
|
245 |
+
higher_bound = np.percentile(bootstrapped_means, 97.5)
|
246 |
+
|
247 |
+
# Calculate the mean value
|
248 |
+
mean_value = np.mean(bootstrapped_means)
|
249 |
+
|
250 |
+
return lower_bound, higher_bound, mean_value
|
251 |
+
|
252 |
# Apply KNN and get predicted Predicted_target values
|
253 |
+
predicted_target = knn_predict(filtered_data, 'Predicted_target', ['latitude', 'longitude', 'area_feature'])
|
254 |
|
255 |
# Check if there are predictions to display
|
256 |
if 'Predicted_target' in filtered_data.columns and not np.all(predicted_target == 0):
|
|
|
260 |
# Display the predicted Predicted_target values
|
261 |
st.write("Valores (R$/m²) previstos com algoritmo KNN:")
|
262 |
st.write(filtered_data[['Localização', 'Atotal', 'Apriv', 'Vunit_total', 'Vunit_priv', 'Predicted_target']])
|
263 |
+
|
264 |
+
# Apply bootstrap on the predicted values
|
265 |
+
lower_bound, higher_bound, mean_value = bootstrap_stats(predicted_target)
|
266 |
+
|
267 |
+
# Display the results
|
268 |
+
st.write(f"Valor médio (R$/m²) para as características selecionadas: {mean_value}")
|
269 |
+
st.write(f"Os valores podem variar entre {lower_bound} e {higher_bound} dependendo das características dos imóveis.")
|
270 |
+
st.write(f"Higher Bound: ")
|
271 |
else:
|
272 |
st.warning(f"Dados insuficientes para inferência do valor. Mínimo necessário: {k_threshold}")
|