fschwartzer commited on
Commit
897ea2d
1 Parent(s): b3053e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -1
app.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
  import pandas as pd
3
  import numpy as np
4
  import openpyxl
 
5
  from geopy.distance import geodesic
6
 
7
  # Set wide mode
@@ -83,4 +84,41 @@ st.markdown(f"""<style>
83
 
84
  # Wrap the map in a container with the custom CSS class
85
  with st.container():
86
- st.map(filtered_data, zoom=zoom_level, use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import pandas as pd
3
  import numpy as np
4
  import openpyxl
5
+ from sklearn.neighbors import KNeighborsRegressor
6
  from geopy.distance import geodesic
7
 
8
  # Set wide mode
 
84
 
85
  # Wrap the map in a container with the custom CSS class
86
  with st.container():
87
+ st.map(filtered_data, zoom=zoom_level, use_container_width=True)
88
+
89
+ # Function to apply KNN and return Vunit values
90
+ def knn_predict(df, target_column, features_columns, k=5):
91
+ # Separate features and target variable
92
+ X = df[features_columns]
93
+ y = df[target_column]
94
+
95
+ # Create KNN regressor
96
+ knn = KNeighborsRegressor(n_neighbors=k)
97
+
98
+ # Fit the model
99
+ knn.fit(X, y)
100
+
101
+ # Use the model to predict Vunit for the filtered_data
102
+ predictions = knn.predict(filtered_data[features_columns])
103
+
104
+ return predictions
105
+
106
+ # Features columns for KNN
107
+ knn_features = ['latitude', 'longitude', 'Area'] # Add other relevant features
108
+
109
+ # Check if KNN should be applied
110
+ if selected_coords == 'Custom' and radius_visible:
111
+ # Apply KNN and get predicted Vunit values
112
+ predicted_vunit = knn_predict(data, 'Vunit', knn_features)
113
+
114
+ # Add predicted Vunit values to filtered_data
115
+ filtered_data['Predicted_Vunit'] = predicted_vunit
116
+
117
+ # Display the map and filtered_data
118
+ with st.container():
119
+ st.map(filtered_data, zoom=zoom_level, use_container_width=True)
120
+
121
+ # Display the predicted Vunit values if applicable
122
+ if 'Predicted_Vunit' in filtered_data.columns:
123
+ st.write("Predicted Vunit Values:")
124
+ st.write(filtered_data[['latitude', 'longitude', 'Vunit', 'Predicted_Vunit']])