File size: 1,184 Bytes
56c732f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import joblib
import numpy as np
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)

# feature names
features = ["MedInc", "HouseAge", "AveRooms", "AveBedrms", "Population", "AveOccup", "Latitude", "Longitude"]

# collect user input
print("Enter feature values!")
user_input = []
for feature in features:
    val = float(input(f"Enter value for {feature}: "))
    user_input.append(val)

# convert to array and scale
user_input = np.array(user_input).reshape(1, -1)
user_input_scaled = scaler.transform(user_input)

# predict and display
prediction = model.predict(user_input_scaled)[0]
predicted_price = prediction * 100000  # target is in 100000s (hundreds of thousands of dollars)
print(f"\nPredicted median house value: ${predicted_price:,.5f}")