-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredict.py
More file actions
31 lines (25 loc) · 730 Bytes
/
predict.py
File metadata and controls
31 lines (25 loc) · 730 Bytes
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
# predict.py
# Load the saved model and make predictions.
import pickle
import pandas as pd
# Load the model and preprocessor
with open('best_model.pkl', 'rb') as f:
model, preprocessor = pickle.load(f)
# Example input for prediction
example_input = {
"MedInc": 8.3252,
"HouseAge": 41.0,
"AveRooms": 6.984127,
"AveBedrms": 1.023810,
"Population": 322.0,
"AveOccup": 2.555556,
"Latitude": 37.88,
"Longitude": -122.23
}
# Convert input to DataFrame
input_df = pd.DataFrame([example_input])
# Preprocess the input data
input_processed = preprocessor.transform(input_df)
# Make prediction
prediction = model.predict(input_processed)
print(f"Predicted Median House Value: {prediction[0]:.4f}")