Update app.py
Browse files
app.py
CHANGED
@@ -7,28 +7,45 @@ model = joblib.load('random_forest_model.pkl') # replace with your model path
|
|
7 |
|
8 |
# Define the function to make predictions
|
9 |
def predict_price(host_id, neighbourhood_group, room_type, number_of_reviews, calculated_host_listings_count, latitude, longitude):
|
10 |
-
#
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
# Set values
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
#
|
29 |
-
custom_data
|
30 |
-
custom_data['room_type_Private room'] = 1 if room_type == 'Private room' else 0
|
31 |
-
custom_data['room_type_Entire home/apt'] = 1 if room_type == 'Entire home/apt' else 0
|
32 |
|
33 |
# Make prediction
|
34 |
predicted_price = model.predict(custom_data)
|
@@ -52,4 +69,4 @@ iface = gr.Interface(
|
|
52 |
)
|
53 |
|
54 |
# Launch the interface
|
55 |
-
iface.launch()
|
|
|
7 |
|
8 |
# Define the function to make predictions
|
9 |
def predict_price(host_id, neighbourhood_group, room_type, number_of_reviews, calculated_host_listings_count, latitude, longitude):
|
10 |
+
# Create a dictionary with default values
|
11 |
+
data = {
|
12 |
+
'host_id': host_id,
|
13 |
+
'number_of_reviews': number_of_reviews,
|
14 |
+
'calculated_host_listings_count': calculated_host_listings_count,
|
15 |
+
'latitude': latitude,
|
16 |
+
'longitude': longitude,
|
17 |
+
# Set dummy values for categorical features
|
18 |
+
'neighbourhood_group_Brooklyn': 0,
|
19 |
+
'neighbourhood_group_Manhattan': 0,
|
20 |
+
'neighbourhood_group_Queens': 0,
|
21 |
+
'neighbourhood_group_Bronx': 0,
|
22 |
+
'neighbourhood_group_Staten Island': 0,
|
23 |
+
'room_type_Shared room': 0,
|
24 |
+
'room_type_Private room': 0,
|
25 |
+
'room_type_Entire home/apt': 0,
|
26 |
+
}
|
27 |
|
28 |
+
# Set appropriate values based on user input
|
29 |
+
if neighbourhood_group == 'Brooklyn':
|
30 |
+
data['neighbourhood_group_Brooklyn'] = 1
|
31 |
+
elif neighbourhood_group == 'Manhattan':
|
32 |
+
data['neighbourhood_group_Manhattan'] = 1
|
33 |
+
elif neighbourhood_group == 'Queens':
|
34 |
+
data['neighbourhood_group_Queens'] = 1
|
35 |
+
elif neighbourhood_group == 'Bronx':
|
36 |
+
data['neighbourhood_group_Bronx'] = 1
|
37 |
+
elif neighbourhood_group == 'Staten Island':
|
38 |
+
data['neighbourhood_group_Staten Island'] = 1
|
39 |
|
40 |
+
if room_type == 'Shared room':
|
41 |
+
data['room_type_Shared room'] = 1
|
42 |
+
elif room_type == 'Private room':
|
43 |
+
data['room_type_Private room'] = 1
|
44 |
+
elif room_type == 'Entire home/apt':
|
45 |
+
data['room_type_Entire home/apt'] = 1
|
46 |
+
|
47 |
+
# Create DataFrame from the dictionary
|
48 |
+
custom_data = pd.DataFrame([data])
|
|
|
|
|
49 |
|
50 |
# Make prediction
|
51 |
predicted_price = model.predict(custom_data)
|
|
|
69 |
)
|
70 |
|
71 |
# Launch the interface
|
72 |
+
iface.launch(share=True) # Set share=True to create a public link
|