time_slot / inference.py
DishaMondal2024's picture
Upload 3 files
33a085f verified
import joblib
import pandas as pd
from sklearn.preprocessing import LabelEncoder
# Load the trained model
model = joblib.load('time_slot_model.joblib')
# Load the LabelEncoder used in training (if applicable)
# label_encoder = joblib.load('label_encoder.joblib') # Uncomment if you used a LabelEncoder
def preprocess_input(user_pref):
# Example preprocessing; adjust based on your actual preprocessing steps
user_input = pd.get_dummies(pd.Series([user_pref]), prefix='Pref')
return user_input
def predict(user_pref):
# Preprocess the input
user_input = preprocess_input(user_pref)
# Ensure the input has the same columns as the training data
user_input = user_input.reindex(columns=model.feature_importances_, fill_value=0)
# Make a prediction
prediction = model.predict(user_input)
return prediction[0]
# Example usage:
# user_pref = 'noon' # Replace with actual user preference
# prediction = predict(user_pref)
# print(f"Predicted next rescheduled time: {prediction}")