File size: 546 Bytes
22ce241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import joblib
import pandas as pd

def predict_price(size, bedrooms, age):
  """Predicts house price based on input features."""
  # Load the model
  model = joblib.load("house_price_model.pkl") 

  # Create a DataFrame from user input
  input_data = pd.DataFrame({
      'Size (sq ft)': [size],
      'Number of Bedrooms': [bedrooms],
      'Age of House (years)': [age]
  })

  # Predict the price using the trained model
  predicted_price = model.predict(input_data)[0]

  # Return the prediction
  return {"predicted_price": predicted_price}