Spaces:
Sleeping
Sleeping
import pandas as pd | |
import joblib | |
# Load model and encoders | |
model = joblib.load("model/model.pkl") | |
encoders = joblib.load("model/encoders.pkl") | |
def predict_transaction(data_dict): | |
# Convert dict to dataframe | |
df = pd.DataFrame([data_dict]) | |
# Process time | |
df["hour"] = pd.to_datetime(df["time"], format="%H:%M").dt.hour | |
df.drop(columns=["check_id", "time"], inplace=True) | |
# Encode categorical features | |
for col in ["employee_id", "terminal_id"]: | |
df[col] = encoders[col].transform(df[col]) | |
# Predict | |
prediction = model.predict(df)[0] | |
return "Suspicious" if prediction == 1 else "Not Suspicious" | |
# Example usage | |
if __name__ == "__main__": | |
sample = { | |
"check_id": 1005, | |
"employee_id": "E101", | |
"total": 100, | |
"discount_amount": 90, | |
"item_count": 1, | |
"time": "12:10", | |
"terminal_id": "T1" | |
} | |
result = predict_transaction(sample) | |
print("Prediction:", result) | |