Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -27,10 +27,10 @@ def predict_employee_status(
|
|
27 |
work_accident, promotion_last_5years, salary, department, threshold=0.5
|
28 |
):
|
29 |
departments = [
|
30 |
-
'
|
31 |
-
'
|
32 |
]
|
33 |
-
|
34 |
# One-hot encode department
|
35 |
department_features = {f"department_{dept}": 0 for dept in departments}
|
36 |
if department in departments:
|
@@ -57,7 +57,7 @@ def predict_employee_status(
|
|
57 |
|
58 |
input_df = pd.DataFrame(input_data)
|
59 |
|
60 |
-
#
|
61 |
expected_columns = [
|
62 |
'satisfaction_level', 'last_evaluation', 'number_project', 'average_monthly_hours',
|
63 |
'time_spend_company', 'Work_accident', 'promotion_last_5years', 'salary',
|
@@ -66,13 +66,11 @@ def predict_employee_status(
|
|
66 |
'department_management', 'department_marketing', 'department_product_mng',
|
67 |
'department_sales', 'department_support', 'department_technical'
|
68 |
]
|
69 |
-
|
70 |
for col in expected_columns:
|
71 |
if col not in input_df.columns:
|
72 |
input_df[col] = 0
|
73 |
input_df = input_df[expected_columns]
|
74 |
|
75 |
-
# Predict
|
76 |
try:
|
77 |
prob = model.predict_proba(input_df)[0][1]
|
78 |
result = "β
Employee is likely to quit." if prob >= threshold else "β
Employee is likely to stay."
|
|
|
27 |
work_accident, promotion_last_5years, salary, department, threshold=0.5
|
28 |
):
|
29 |
departments = [
|
30 |
+
'IT', 'RandD', 'accounting', 'hr', 'management',
|
31 |
+
'marketing', 'product_mng', 'sales', 'support', 'technical'
|
32 |
]
|
33 |
+
|
34 |
# One-hot encode department
|
35 |
department_features = {f"department_{dept}": 0 for dept in departments}
|
36 |
if department in departments:
|
|
|
57 |
|
58 |
input_df = pd.DataFrame(input_data)
|
59 |
|
60 |
+
# Ensure exact column order
|
61 |
expected_columns = [
|
62 |
'satisfaction_level', 'last_evaluation', 'number_project', 'average_monthly_hours',
|
63 |
'time_spend_company', 'Work_accident', 'promotion_last_5years', 'salary',
|
|
|
66 |
'department_management', 'department_marketing', 'department_product_mng',
|
67 |
'department_sales', 'department_support', 'department_technical'
|
68 |
]
|
|
|
69 |
for col in expected_columns:
|
70 |
if col not in input_df.columns:
|
71 |
input_df[col] = 0
|
72 |
input_df = input_df[expected_columns]
|
73 |
|
|
|
74 |
try:
|
75 |
prob = model.predict_proba(input_df)[0][1]
|
76 |
result = "β
Employee is likely to quit." if prob >= threshold else "β
Employee is likely to stay."
|