Upload house_price_prediction.py with huggingface_hub
Browse files- house_price_prediction.py +20 -0
house_price_prediction.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import joblib
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
def predict_price(size, bedrooms, age):
|
5 |
+
"""Predicts house price based on input features."""
|
6 |
+
# Load the model
|
7 |
+
model = joblib.load("house_price_model.pkl")
|
8 |
+
|
9 |
+
# Create a DataFrame from user input
|
10 |
+
input_data = pd.DataFrame({
|
11 |
+
'Size (sq ft)': [size],
|
12 |
+
'Number of Bedrooms': [bedrooms],
|
13 |
+
'Age of House (years)': [age]
|
14 |
+
})
|
15 |
+
|
16 |
+
# Predict the price using the trained model
|
17 |
+
predicted_price = model.predict(input_data)[0]
|
18 |
+
|
19 |
+
# Return the prediction
|
20 |
+
return {"predicted_price": predicted_price}
|