Update app.py
Browse files
app.py
CHANGED
@@ -85,105 +85,6 @@ def main():
|
|
85 |
prediction = model.predict(input_data)
|
86 |
probability = model.predict_proba(input_data)[:, 1]
|
87 |
|
88 |
-
# Display prediction
|
89 |
-
if prediction[0] == 0:
|
90 |
-
st.success("Employee is predicted to stay (Attrition = No)")
|
91 |
-
else:
|
92 |
-
st.error("Employee is predicted to leave (Attrition = Yes)")
|
93 |
-
|
94 |
-
# Offer recommendations for retaining the employee
|
95 |
-
st.subheader("Suggestions for retaining the employee:")
|
96 |
-
st.markdown("- Invest in orientation programs and career development for entry-level staff, which could contribute to higher retention.")
|
97 |
-
st.markdown("- Implement mentorship programs and career development initiatives aimed at engaging and retaining younger employees.")
|
98 |
-
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.")
|
99 |
-
st.markdown("- Recognize the diverse needs of employees based on marital status and consider tailoring benefits or support programs accordingly.")
|
100 |
-
st.markdown("- Consider offering benefits that cater to the unique needs of married, single, and divorced employees.")
|
101 |
-
st.markdown("- Introduce or enhance policies that support work-life balance for employees with families.")
|
102 |
-
st.markdown("- Recognize the unique challenges and opportunities within each department and tailor retention strategies accordingly.")
|
103 |
-
|
104 |
-
# Display probability
|
105 |
-
st.write(f"Probability of Attrition: {probability[0]:.2f}")
|
106 |
-
|
107 |
-
if __name__ == "__main__":
|
108 |
-
main()
|
109 |
-
import streamlit as st
|
110 |
-
import pickle
|
111 |
-
import pandas as pd
|
112 |
-
from catboost import CatBoostClassifier
|
113 |
-
|
114 |
-
# Load the trained model and unique values from the pickle file
|
115 |
-
with open('model_and_key_components.pkl', 'rb') as file:
|
116 |
-
saved_components = pickle.load(file)
|
117 |
-
|
118 |
-
model = saved_components['model']
|
119 |
-
unique_values = saved_components['unique_values']
|
120 |
-
|
121 |
-
# Define the Streamlit app
|
122 |
-
def main():
|
123 |
-
st.title("Employee Attrition Prediction App")
|
124 |
-
st.sidebar.title("Model Settings")
|
125 |
-
|
126 |
-
# Sidebar inputs
|
127 |
-
with st.sidebar.expander("View Unique Values"):
|
128 |
-
st.write("Unique values for each feature:")
|
129 |
-
for column, values in unique_values.items():
|
130 |
-
st.write(f"- {column}: {values}")
|
131 |
-
|
132 |
-
# Main content
|
133 |
-
st.write("Welcome to the Employee Attrition Prediction App!")
|
134 |
-
st.write("This app helps HR practitioners predict employee attrition using a trained CatBoost model.")
|
135 |
-
st.write("Please provide the following information to make a prediction:")
|
136 |
-
|
137 |
-
# Define layout with three columns
|
138 |
-
col1, col2, col3 = st.columns(3)
|
139 |
-
|
140 |
-
# Column 1
|
141 |
-
with col1:
|
142 |
-
age = st.number_input("Age", min_value=18, max_value=70)
|
143 |
-
monthly_income = st.number_input("Monthly Income", min_value=1000, max_value=20000)
|
144 |
-
num_companies_worked = st.number_input("Number of Companies Worked", min_value=0, max_value=10)
|
145 |
-
percent_salary_hike = st.number_input("Percent Salary Hike", min_value=10, max_value=25)
|
146 |
-
training_times_last_year = st.number_input("Training Times Last Year", min_value=0, max_value=6)
|
147 |
-
|
148 |
-
# Column 2
|
149 |
-
with col2:
|
150 |
-
department = st.selectbox("Department", ['Sales', 'Research & Development', 'Human Resources'])
|
151 |
-
environment_satisfaction = st.selectbox("Environment Satisfaction", [1, 2, 3, 4])
|
152 |
-
job_role = st.selectbox("Job Role", ['Sales Executive', 'Research Scientist', 'Laboratory Technician',
|
153 |
-
'Manufacturing Director', 'Healthcare Representative', 'Manager',
|
154 |
-
'Sales Representative', 'Research Director', 'Human Resources'])
|
155 |
-
job_satisfaction = st.selectbox("Job Satisfaction", [1, 2, 3, 4])
|
156 |
-
work_life_balance = st.selectbox("Work Life Balance", [1, 2, 3, 4])
|
157 |
-
|
158 |
-
# Column 3
|
159 |
-
with col3:
|
160 |
-
over_time = st.checkbox("Over Time")
|
161 |
-
relationship_satisfaction = st.selectbox("Relationship Satisfaction", [1, 2, 3, 4])
|
162 |
-
years_since_last_promotion = st.number_input("Years Since Last Promotion", min_value=0, max_value=15)
|
163 |
-
years_with_curr_manager = st.number_input("Years With Current Manager", min_value=0, max_value=15)
|
164 |
-
|
165 |
-
# Create a DataFrame to hold the user input data
|
166 |
-
input_data = pd.DataFrame({
|
167 |
-
'Age': [age],
|
168 |
-
'Department': [department],
|
169 |
-
'EnvironmentSatisfaction': [environment_satisfaction],
|
170 |
-
'JobRole': [job_role],
|
171 |
-
'JobSatisfaction': [job_satisfaction],
|
172 |
-
'MonthlyIncome': [monthly_income],
|
173 |
-
'NumCompaniesWorked': [num_companies_worked],
|
174 |
-
'OverTime': [over_time],
|
175 |
-
'PercentSalaryHike': [percent_salary_hike],
|
176 |
-
'RelationshipSatisfaction': [relationship_satisfaction],
|
177 |
-
'TrainingTimesLastYear': [training_times_last_year],
|
178 |
-
'WorkLifeBalance': [work_life_balance],
|
179 |
-
'YearsSinceLastPromotion': [years_since_last_promotion],
|
180 |
-
'YearsWithCurrManager': [years_with_curr_manager]
|
181 |
-
})
|
182 |
-
|
183 |
-
# Make predictions
|
184 |
-
prediction = model.predict(input_data)
|
185 |
-
probability = model.predict_proba(input_data)[:, 1]
|
186 |
-
|
187 |
# Display prediction
|
188 |
if prediction[0] == 0:
|
189 |
st.success("Employee is predicted to stay (Attrition = No)")
|
|
|
85 |
prediction = model.predict(input_data)
|
86 |
probability = model.predict_proba(input_data)[:, 1]
|
87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
# Display prediction
|
89 |
if prediction[0] == 0:
|
90 |
st.success("Employee is predicted to stay (Attrition = No)")
|