-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredict.py
More file actions
43 lines (33 loc) · 1.08 KB
/
Copy pathpredict.py
File metadata and controls
43 lines (33 loc) · 1.08 KB
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
"""
Prediction script for classification model
This script loads a trained model and makes predictions on new data.
"""
import pandas as pd
import pickle
# Load the trained model
with open('classification_model_20260204_020217.pkl', 'rb') as f:
saved_data = pickle.load(f)
model = saved_data['model']
scaler = saved_data['scaler']
label_encoder = saved_data.get('label_encoder')
# Load new data for prediction
# TODO: Update this path to your new data
new_data = pd.read_csv('new_data.csv')
# Prepare data (same preprocessing as training)
X = pd.get_dummies(new_data, drop_first=True)
X = X.fillna(X.mean())
# Scale features
X_scaled = scaler.transform(X)
# Make predictions
predictions = model.predict(X_scaled)
# Decode if classification with label encoder
if label_encoder is not None:
predictions = label_encoder.inverse_transform(predictions)
# Save predictions
result_df = pd.DataFrame({
'predictions': predictions
})
result_df.to_csv('predictions.csv', index=False)
print("Predictions saved to predictions.csv")
print("\nFirst few predictions:")
print(result_df.head())