house-price-prediction-model / USAGE_EXAMPLE.md
RayyanAhmed9477's picture
Upload USAGE_EXAMPLE.md with huggingface_hub
3471028 verified

Usage Example

Installation

pip install huggingface_hub

Loading the Model

from huggingface_hub import hf_hub_download
import pickle

# Download and load the model
model_path = hf_hub_download(
    repo_id="RayyanAhmed9477/house-price-prediction-model",
    filename="house_price_model.pkl"
)

with open(model_path, 'rb') as f:
    model_data = pickle.load(f)

Making Predictions

import pandas as pd

# Prepare input data
input_data = pd.DataFrame([{
    "property_type": "House",
    "location": "DHA Defence", 
    "city": "Lahore",
    "baths": 3,
    "purpose": "For Sale",
    "bedrooms": 4,
    "Area_in_Marla": 5.0
}])

# Encode categorical variables
for col in ["property_type", "location", "city", "purpose"]:
    if col in model_data["label_encoders"]:
        le = model_data["label_encoders"][col]
        try:
            input_data[col] = le.transform([str(input_data[col].iloc[0])])
        except ValueError:
            # Handle unknown categories
            input_data[col] = le.transform([le.classes_[0]])

# Make prediction
prediction = model_data["model"].predict(input_data[model_data["feature_columns"]])[0]
print(f"Predicted Price: {prediction}")