File size: 1,718 Bytes
9abcb1f 1065c08 9abcb1f 1065c08 9abcb1f 1065c08 4a9afed 1065c08 9abcb1f 93f3ec9 1065c08 93f3ec9 1065c08 93f3ec9 1065c08 |
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
---
license: mit
---
# ML Assignment 3 – Maha Qaiser
Dataset: California Housing from sklearn.datasets
## File Description
- `best_model.joblib`: Mini-Batch Linear Regression model
- `scaler.joblib`: StandardScaler object to preprocess input features
- `inference.py`: Script to load the model + scaler and run predictions with user input
## Model Overview
- **Model Type:** Mini-Batch Linear Regression
- **Features Used:**
- Avg. Rooms
- Avg. Bedrooms
- Population
- Household
- Median Income
- Latitude
- Longitude
- Housing Median Age
- **Regularization:** L2 (Ridge)
- **Early Stopping:** Applied during training
## How to Run Inference
### 1. Clone the repository or download the files:
```bash
git clone https://huggingface.co/mahaqj/ml_assignment_3
cd ml_assignment_3
```
### 2. Install dependencies:
```bash
pip install joblib numpy scikit-learn huggingface_hub
```
### 3. Run the script:
```bash
python inference.py
```
You’ll be prompted to enter the following features:
- Avg. Rooms
- Avg. Bedrooms
- Population
- Household
- Median Income
- Latitude
- Longitude
- Housing Median Age
The model will return the predicted housing value.
## Loading the Model in Python
```python
import joblib
import requests
from io import BytesIO
# urls to both model and scaler
model_url = "https://huggingface.co/mahaqj/ml_assignment_3/resolve/main/best_model.joblib"
scaler_url = "https://huggingface.co/mahaqj/ml_assignment_3/resolve/main/scaler.joblib"
# download and load model
model_bytes = BytesIO(requests.get(model_url).content)
model = joblib.load(model_bytes)
# download and load scaler
scaler_bytes = BytesIO(requests.get(scaler_url).content)
scaler = joblib.load(scaler_bytes)
``` |