File size: 1,280 Bytes
3471028
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

# Usage Example

## Installation
```bash

pip install huggingface_hub

```

## Loading the Model
```python

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
```python

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}")

```