Upload USAGE_EXAMPLE.md with huggingface_hub
Browse files- USAGE_EXAMPLE.md +53 -0
USAGE_EXAMPLE.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# Usage Example
|
| 3 |
+
|
| 4 |
+
## Installation
|
| 5 |
+
```bash
|
| 6 |
+
pip install huggingface_hub
|
| 7 |
+
```
|
| 8 |
+
|
| 9 |
+
## Loading the Model
|
| 10 |
+
```python
|
| 11 |
+
from huggingface_hub import hf_hub_download
|
| 12 |
+
import pickle
|
| 13 |
+
|
| 14 |
+
# Download and load the model
|
| 15 |
+
model_path = hf_hub_download(
|
| 16 |
+
repo_id="RayyanAhmed9477/house-price-prediction-model",
|
| 17 |
+
filename="house_price_model.pkl"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
with open(model_path, 'rb') as f:
|
| 21 |
+
model_data = pickle.load(f)
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
## Making Predictions
|
| 25 |
+
```python
|
| 26 |
+
import pandas as pd
|
| 27 |
+
|
| 28 |
+
# Prepare input data
|
| 29 |
+
input_data = pd.DataFrame([{
|
| 30 |
+
"property_type": "House",
|
| 31 |
+
"location": "DHA Defence",
|
| 32 |
+
"city": "Lahore",
|
| 33 |
+
"baths": 3,
|
| 34 |
+
"purpose": "For Sale",
|
| 35 |
+
"bedrooms": 4,
|
| 36 |
+
"Area_in_Marla": 5.0
|
| 37 |
+
}])
|
| 38 |
+
|
| 39 |
+
# Encode categorical variables
|
| 40 |
+
for col in ["property_type", "location", "city", "purpose"]:
|
| 41 |
+
if col in model_data["label_encoders"]:
|
| 42 |
+
le = model_data["label_encoders"][col]
|
| 43 |
+
try:
|
| 44 |
+
input_data[col] = le.transform([str(input_data[col].iloc[0])])
|
| 45 |
+
except ValueError:
|
| 46 |
+
# Handle unknown categories
|
| 47 |
+
input_data[col] = le.transform([le.classes_[0]])
|
| 48 |
+
|
| 49 |
+
# Make prediction
|
| 50 |
+
prediction = model_data["model"].predict(input_data[model_data["feature_columns"]])[0]
|
| 51 |
+
print(f"Predicted Price: {prediction}")
|
| 52 |
+
```
|
| 53 |
+
|