fahad1995 commited on
Commit
e1b08fc
·
verified ·
1 Parent(s): db03ce6
Files changed (1) hide show
  1. app.py +14 -23
app.py CHANGED
@@ -5,22 +5,11 @@ import joblib
5
  # Load your Random Forest model
6
  loaded_model = joblib.load('random_forest_model.pkl')
7
 
8
- # Define the expected feature columns
9
- feature_columns = [
10
- 'host_id',
11
- 'latitude',
12
- 'longitude',
13
- 'number_of_reviews',
14
- 'calculated_host_listings_count',
15
- 'room_type_Entire home/apt',
16
- 'room_type_Private room',
17
- 'room_type_Shared room',
18
- 'neighbourhood_group_Bronx',
19
- 'neighbourhood_group_Brooklyn',
20
- 'neighbourhood_group_Manhattan',
21
- 'neighbourhood_group_Queens',
22
- 'neighbourhood_group_Staten Island',
23
- ]
24
 
25
  # Function to make predictions
26
  def predict(host_id, neighbourhood_group, neighbourhood, room_type, latitude, longitude, number_of_reviews, calculated_host_listings_count):
@@ -40,7 +29,7 @@ def predict(host_id, neighbourhood_group, neighbourhood, room_type, latitude, lo
40
  input_data = pd.get_dummies(input_data, columns=['room_type', 'neighbourhood_group', 'neighbourhood'], drop_first=True)
41
 
42
  # Ensure the input data has the same columns as the training data
43
- input_data = input_data.reindex(columns=feature_columns, fill_value=0)
44
 
45
  # Make the prediction
46
  predicted_price = loaded_model.predict(input_data)
@@ -51,16 +40,18 @@ iface = gr.Interface(
51
  fn=predict,
52
  inputs=[
53
  gr.Number(label="Host ID"),
54
- gr.Dropdown(label="Neighbourhood Group", choices=['Bronx', 'Brooklyn', 'Manhattan', 'Queens', 'Staten Island']),
55
- gr.Dropdown(label="Neighbourhood", choices=['Chelsea', 'Flatiron District', 'Upper West Side', 'East Village', '...']),
56
- gr.Dropdown(label="Room Type", choices=['Entire home/apt', 'Private room', 'Shared room']),
57
  gr.Number(label="Latitude"),
58
  gr.Number(label="Longitude"),
59
  gr.Number(label="Number of Reviews"),
60
- gr.Number(label="Calculated Host Listings Count"),
61
  ],
62
- outputs="number",
 
 
63
  )
64
 
65
- # Launch the Gradio app
66
  iface.launch()
 
5
  # Load your Random Forest model
6
  loaded_model = joblib.load('random_forest_model.pkl')
7
 
8
+ # Example: Define the training DataFrame X (replace with your actual training data)
9
+ # This should be a DataFrame with the same structure as your training data
10
+ X = pd.DataFrame(columns=['host_id', 'neighbourhood_group', 'neighbourhood', 'room_type',
11
+ 'latitude', 'longitude', 'number_of_reviews',
12
+ 'calculated_host_listings_count']) # Add one-hot encoded columns as well
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  # Function to make predictions
15
  def predict(host_id, neighbourhood_group, neighbourhood, room_type, latitude, longitude, number_of_reviews, calculated_host_listings_count):
 
29
  input_data = pd.get_dummies(input_data, columns=['room_type', 'neighbourhood_group', 'neighbourhood'], drop_first=True)
30
 
31
  # Ensure the input data has the same columns as the training data
32
+ input_data = input_data.reindex(columns=X.columns, fill_value=0)
33
 
34
  # Make the prediction
35
  predicted_price = loaded_model.predict(input_data)
 
40
  fn=predict,
41
  inputs=[
42
  gr.Number(label="Host ID"),
43
+ gr.Dropdown(label="Neighbourhood Group", choices=["Manhattan", "Brooklyn", "Queens", "Staten Island", "Bronx"]),
44
+ gr.Dropdown(label="Neighbourhood", choices=["Chelsea", "East Village", "Midtown", "SoHo", "Williamsburg"]), # Add actual neighbourhood options
45
+ gr.Dropdown(label="Room Type", choices=["Entire home/apt", "Private room", "Shared room"]),
46
  gr.Number(label="Latitude"),
47
  gr.Number(label="Longitude"),
48
  gr.Number(label="Number of Reviews"),
49
+ gr.Number(label="Calculated Host Listings Count")
50
  ],
51
+ outputs=gr.Number(label="Predicted Price"),
52
+ title="Airbnb Price Prediction",
53
+ description="Enter the details of the Airbnb listing to predict the price."
54
  )
55
 
56
+ # Launch the interface
57
  iface.launch()