Update app.py
Browse files
app.py
CHANGED
@@ -54,61 +54,63 @@ def main():
|
|
54 |
years_since_last_promotion = st.number_input("Years Since Last Promotion")
|
55 |
years_with_curr_manager = st.number_input("Years With Current Manager")
|
56 |
|
57 |
-
#
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
112 |
|
113 |
if __name__ == "__main__":
|
114 |
main()
|
|
|
54 |
years_since_last_promotion = st.number_input("Years Since Last Promotion")
|
55 |
years_with_curr_manager = st.number_input("Years With Current Manager")
|
56 |
|
57 |
+
# Predict button
|
58 |
+
if st.button("Predict"):
|
59 |
+
# Convert numerical features to strings
|
60 |
+
age = str(age)
|
61 |
+
monthly_income = str(monthly_income)
|
62 |
+
num_companies_worked = str(num_companies_worked)
|
63 |
+
percent_salary_hike = str(percent_salary_hike)
|
64 |
+
training_times_last_year = str(training_times_last_year)
|
65 |
+
years_since_last_promotion = str(years_since_last_promotion)
|
66 |
+
years_with_curr_manager = str(years_with_curr_manager)
|
67 |
+
|
68 |
+
# Create a DataFrame to hold the user input data
|
69 |
+
input_data = pd.DataFrame({
|
70 |
+
'Age': [age],
|
71 |
+
'Department': [department],
|
72 |
+
'EnvironmentSatisfaction': [environment_satisfaction],
|
73 |
+
'JobRole': [job_role],
|
74 |
+
'JobSatisfaction': [job_satisfaction],
|
75 |
+
'MonthlyIncome': [monthly_income],
|
76 |
+
'NumCompaniesWorked': [num_companies_worked],
|
77 |
+
'OverTime': [over_time],
|
78 |
+
'PercentSalaryHike': [percent_salary_hike],
|
79 |
+
'RelationshipSatisfaction': [relationship_satisfaction],
|
80 |
+
'TrainingTimesLastYear': [training_times_last_year],
|
81 |
+
'WorkLifeBalance': [work_life_balance],
|
82 |
+
'YearsSinceLastPromotion': [years_since_last_promotion],
|
83 |
+
'YearsWithCurrManager': [years_with_curr_manager]
|
84 |
+
})
|
85 |
+
|
86 |
+
# Reorder columns to match the expected order
|
87 |
+
input_data = input_data[['Age', 'Department', 'EnvironmentSatisfaction', 'JobRole', 'JobSatisfaction',
|
88 |
+
'MonthlyIncome', 'NumCompaniesWorked', 'OverTime', 'PercentSalaryHike',
|
89 |
+
'RelationshipSatisfaction', 'TrainingTimesLastYear', 'WorkLifeBalance',
|
90 |
+
'YearsSinceLastPromotion', 'YearsWithCurrManager']]
|
91 |
+
|
92 |
+
# Make predictions
|
93 |
+
prediction = model.predict(input_data)
|
94 |
+
probability = model.predict_proba(input_data)[:, 1]
|
95 |
+
|
96 |
+
# Display prediction
|
97 |
+
if prediction[0] == 0:
|
98 |
+
st.success("Employee is predicted to stay (Attrition = No)")
|
99 |
+
else:
|
100 |
+
st.error("Employee is predicted to leave (Attrition = Yes)")
|
101 |
+
|
102 |
+
# Offer recommendations for retaining the employee
|
103 |
+
st.subheader("Suggestions for retaining the employee:")
|
104 |
+
st.markdown("- Invest in orientation programs and career development for entry-level staff, which could contribute to higher retention.")
|
105 |
+
st.markdown("- Implement mentorship programs and career development initiatives aimed at engaging and retaining younger employees.")
|
106 |
+
st.markdown("- Offer robust training and development programs and regular promotions to foster career growth. This investment in skills and career advancement can contribute to higher job satisfaction and retention.")
|
107 |
+
st.markdown("- Recognize the diverse needs of employees based on marital status and consider tailoring benefits or support programs accordingly.")
|
108 |
+
st.markdown("- Consider offering benefits that cater to the unique needs of married, single, and divorced employees.")
|
109 |
+
st.markdown("- Introduce or enhance policies that support work-life balance for employees with families.")
|
110 |
+
st.markdown("- Recognize the unique challenges and opportunities within each department and tailor retention strategies accordingly.")
|
111 |
+
|
112 |
+
# Display probability
|
113 |
+
st.write(f"Probability of Attrition: {probability[0]*100:.2f}%")
|
114 |
|
115 |
if __name__ == "__main__":
|
116 |
main()
|