Spaces:
Sleeping
Sleeping
File size: 972 Bytes
0f1b324 |
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 |
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)
|