Gieorgie commited on
Commit
902db92
1 Parent(s): 7a53b41

Update prediction.py

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