rasmodev commited on
Commit
292f81f
·
verified ·
1 Parent(s): 72c24fa

Update app.py

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