Update prediction.py
Browse files- prediction.py +77 -71
prediction.py
CHANGED
@@ -1,71 +1,77 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
import pickle
|
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 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
'
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
'
|
47 |
-
'
|
48 |
-
'
|
49 |
-
'
|
50 |
-
'
|
51 |
-
'
|
52 |
-
'
|
53 |
-
'
|
54 |
-
'
|
55 |
-
'
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import pickle
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
# Path to the model file
|
7 |
+
model_path = "model.pkl"
|
8 |
+
|
9 |
+
# Load the model
|
10 |
+
with open(model_path, 'rb') as f:
|
11 |
+
model = pickle.load(f)
|
12 |
+
|
13 |
+
def run():
|
14 |
+
st.title('Prediksi Pengunduran Diri Karyawan')
|
15 |
+
st.markdown('---')
|
16 |
+
image = Image.open('image_prediction.jpg')
|
17 |
+
st.image(image)
|
18 |
+
# Membuat Garis lurus
|
19 |
+
st.markdown('---')
|
20 |
+
|
21 |
+
# Formulir untuk pengisian data
|
22 |
+
with st.form('form_employee_attrition'):
|
23 |
+
# Kolom input sesuai dengan keterangan yang Anda berikan
|
24 |
+
business_travel = st.selectbox('Business Travel', ['Travel_Rarely', 'Travel_Frequently', 'Non-Travel'])
|
25 |
+
department = st.selectbox('Department', ['Sales', 'Research & Development', 'Human Resources'])
|
26 |
+
education_field = st.selectbox('Education Field', ['Life Sciences', 'Other', 'Medical', 'Marketing', 'Technical Degree', 'Human Resources'])
|
27 |
+
job_role = st.selectbox('Job Role', ['Healthcare Representative', 'Research Scientist', 'Sales Executive', 'Human Resources', 'Research Director', 'Laboratory Technician', 'Manufacturing Director', 'Sales Representative', 'Manager'])
|
28 |
+
marital_status = st.selectbox('Marital Status', ['Married', 'Single', 'Divorced'])
|
29 |
+
training_times_last_year = st.selectbox('Training Times Last Year', [0, 1, 2, 3, 4, 5, 6])
|
30 |
+
job_involvement = st.selectbox('Job Involvement', [1, 2, 3, 4], format_func=lambda x: {1: 'Low', 2: 'Medium', 3: 'High', 4: 'Very High'}[x])
|
31 |
+
environment_satisfaction = st.selectbox('Environment Satisfaction', [1, 2, 3, 4], format_func=lambda x: {1: 'Low', 2: 'Medium', 3: 'High', 4: 'Very High'}[x])
|
32 |
+
job_satisfaction = st.selectbox('Job Satisfaction', [1, 2, 3, 4], format_func=lambda x: {1: 'Low', 2: 'Medium', 3: 'High', 4: 'Very High'}[x])
|
33 |
+
work_life_balance = st.selectbox('Work Life Balance', [1, 2, 3, 4], format_func=lambda x: {1: 'Bad', 2: 'Good', 3: 'Better', 4: 'Best'}[x])
|
34 |
+
age = st.slider('Age', min_value=18, max_value=60)
|
35 |
+
percent_salary_hike = st.slider('Percent Salary Hike', min_value=11, max_value=25)
|
36 |
+
total_working_years = st.slider('Total Working Years', min_value=0, max_value=40)
|
37 |
+
years_at_company = st.slider('Years At Company', min_value=0, max_value=40)
|
38 |
+
years_since_last_promotion = st.slider('Years Since Last Promotion', min_value=0, max_value=15)
|
39 |
+
years_with_curr_manager = st.slider('Years With Current Manager', min_value=0, max_value=17)
|
40 |
+
|
41 |
+
# Tombol untuk melakukan prediksi
|
42 |
+
submitted = st.form_submit_button('Prediksi')
|
43 |
+
|
44 |
+
# Menyusun data input menjadi DataFrame
|
45 |
+
data = {
|
46 |
+
'BusinessTravel': business_travel,
|
47 |
+
'Department': department,
|
48 |
+
'EducationField': education_field,
|
49 |
+
'JobRole': job_role,
|
50 |
+
'MaritalStatus': marital_status,
|
51 |
+
'TrainingTimesLastYear': training_times_last_year,
|
52 |
+
'JobInvolvement': job_involvement,
|
53 |
+
'EnvironmentSatisfaction': environment_satisfaction,
|
54 |
+
'JobSatisfaction': job_satisfaction,
|
55 |
+
'WorkLifeBalance': work_life_balance,
|
56 |
+
'Age': age,
|
57 |
+
'PercentSalaryHike': percent_salary_hike,
|
58 |
+
'TotalWorkingYears': total_working_years,
|
59 |
+
'YearsAtCompany': years_at_company,
|
60 |
+
'YearsSinceLastPromotion': years_since_last_promotion,
|
61 |
+
'YearsWithCurrManager': years_with_curr_manager
|
62 |
+
}
|
63 |
+
|
64 |
+
features = pd.DataFrame(data, index=[0])
|
65 |
+
|
66 |
+
# Menampilkan fitur input pengguna
|
67 |
+
st.write("## Fitur Input Pengguna")
|
68 |
+
st.write(features)
|
69 |
+
|
70 |
+
# Melakukan prediksi jika tombol prediksi ditekan
|
71 |
+
if submitted:
|
72 |
+
prediction = model.predict(features)
|
73 |
+
st.subheader('Hasil Prediksi')
|
74 |
+
st.write('Pengunduran Diri Karyawan:', 'Ya' if prediction[0] == 1 else 'Tidak')
|
75 |
+
|
76 |
+
if __name__ == '__main__':
|
77 |
+
run()
|