Views
No views yet
1import pickle
2import pandas as pd
3from huggingface_hub import hf_hub_download
4
5# Download and load the model from Hugging Face
6model_path = hf_hub_download(
7 repo_id="RayyanAhmed9477/house-price-prediction-model",
8 filename="house_price_model.pkl"
9)
10
11# Load the model
12with open(model_path, 'rb') as f:
13 model_data = pickle.load(f)
14
15# Prepare input data
16input_data = pd.DataFrame([{
17 'property_type': 'House',
18 'location': 'DHA Defence',
19 'city': 'Lahore',
20 'baths': 3,
21 'purpose': 'For Sale',
22 'bedrooms': 4,
23 'Area_in_Marla': 5.0
24}])
25
26# Encode categorical variables
27for col in ['property_type', 'location', 'city', 'purpose']:
28 if col in model_data['label_encoders']:
29 le = model_data['label_encoders'][col]
30 try:
31 input_data[col] = le.transform([str(input_data[col].iloc[0])])
32 except ValueError:
33 # Handle unknown categories by using the most frequent one
34 input_data[col] = le.transform([le.classes_[0]])
35
36# Make prediction
37prediction = model_data['model'].predict(input_data[model_data['feature_columns']])[0]
38print(f"Predicted Price: {prediction}")House Price Prediction Model by Rayyan Ahmed
Available at: https://huggingface.co/RayyanAhmed9477/house-price-prediction-model