aephiday commited on
Commit
7d408f4
·
verified ·
1 Parent(s): 6f89518

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +104 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,106 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
+ # import joblib
4
+ import pickle
5
+
6
+ # scaler = joblib.load('scaler.pkl')
7
+ with open('scaler.pkl', 'rb') as file:
8
+ scaler = pickle.load(file)
9
+ with open('credit_default.pkl', 'rb') as file:
10
+ model = pickle.load(file)
11
+
12
+ st.title('Prediksi Default Loan Customer')
13
+
14
+ Name = st.text_input('Name', placeholder='Input Your Name..')
15
+
16
+ # Streamlit input widgets
17
+ GENDER = st.radio("Jenis Kelamin", ["Laki-laki", "Perempuan"])
18
+ AGE = st.slider('Umur (Tahun)', 0, 130, 20)
19
+ Type_Occupation = st.selectbox(
20
+ "Jenis Pekerjaan",
21
+ ("High skill tech staff", 'Core staff', 'Sales staff', 'Laborers',
22
+ 'Cooking staff', 'Managers', 'Accountants', 'Cleaning staff', 'Drivers',
23
+ 'Private service staff', 'Low-skill Laborers', 'IT staff',
24
+ 'Waiters/barmen staff', 'Medicine staff', 'Security staff', 'HR staff',
25
+ 'Secretaries', 'Realty agents'),
26
+ placeholder="Pilih Pekerjaanmu...",
27
+ )
28
+ Marital_status = st.selectbox(
29
+ "Status Pernikahan",
30
+ ('Married', 'Single / not married', 'Civil marriage', 'Separated', 'Widow'),
31
+ placeholder="Pilih Jenis Pendapatanmu...",
32
+ )
33
+ Family_Members = st.slider('Jumlah Anggota Keluarga', 0, 20, 2)
34
+ Type_Income = st.selectbox(
35
+ "Jenis Pendapatan",
36
+ ('Commercial associate', 'Pensioner', 'Working', 'State servant'),
37
+ placeholder="Pilih Jenis Pendapatanmu...",
38
+ )
39
+ YEAR_EMPLOYED = st.slider('Lama Bekerja (Tahun)', 0, 60, 5)
40
+ EDUCATION = st.selectbox(
41
+ "Pendidikan",
42
+ ('Higher education', 'Secondary / secondary special', 'Lower secondary',
43
+ 'Incomplete higher', 'Academic degree'),
44
+ placeholder="Pilih Pendidikan Terakhirmu...",
45
+ )
46
+ Housing_type = st.selectbox(
47
+ "Tipe Rumah",
48
+ ('House / apartment', 'With parents', 'Rented apartment',
49
+ 'Municipal apartment', 'Co-op apartment', 'Office apartment'),
50
+ placeholder="Pilih Tipe Rumahmu...",
51
+ )
52
+
53
+ # Mapping dictionaries
54
+ Housing_type_map = {
55
+ 'House / apartment': 0, 'Rented apartment': 1, 'With parents': 2,
56
+ 'Municipal apartment': 3, 'Co-op apartment': 4, 'Office apartment': 5
57
+ }
58
+ EDUCATION_map = {
59
+ 'Higher education': 0, 'Secondary / secondary special': 1, 'Lower secondary': 2,
60
+ 'Incomplete higher': 3, 'Academic degree': 4
61
+ }
62
+ Type_Occupation_map = {
63
+ 'Private service staff': 0, 'Laborers': 1, 'Managers': 2, 'Medicine staff': 3,
64
+ 'Cooking staff': 4, 'Sales staff': 5, 'Accountants': 6, 'High skill tech staff': 7,
65
+ 'Cleaning staff': 8, 'Drivers': 9, 'Low-skill Laborers': 10, 'IT staff': 11,
66
+ 'Waiters/barmen staff': 12, 'Core staff': 13, 'Security staff': 14, 'HR staff': 15,
67
+ 'Secretaries': 16, 'Realty agents': 17
68
+ }
69
+ GENDER_map = {'Laki-laki': 1, 'Perempuan': 0}
70
+ Marital_status_map = {
71
+ 'Married': 0, 'Single / not married': 1, 'Civil marriage': 2, 'Separated': 3, 'Widow': 4
72
+ }
73
+ Type_Income_map = {
74
+ 'Commercial associate': 0, 'Pensioner': 1, 'Working': 2, 'State servant': 3
75
+ }
76
+
77
+ df = pd.DataFrame()
78
+
79
+ if st.button('Prediksi Loan Customer'):
80
+ Name = Name
81
+ Housing_type_value = Housing_type_map[Housing_type]
82
+ EDUCATION_value = EDUCATION_map[EDUCATION]
83
+ Type_Occupation_value = Type_Occupation_map[Type_Occupation]
84
+ GENDER_value = GENDER_map[GENDER]
85
+ Marital_status_value = Marital_status_map[Marital_status]
86
+ Type_Income_value = Type_Income_map[Type_Income]
87
+
88
+ card_credit = [GENDER_value, Type_Occupation_value, Type_Income_value, Marital_status_value, EDUCATION_value, AGE, Housing_type_value, YEAR_EMPLOYED]
89
 
90
+ df = pd.DataFrame([card_credit], columns=['GENDER', 'Type_Occupation', 'Type_Income', 'Marital_status', 'EDUCATION', 'AGE', 'Housing_type', 'YEAR_EMPLOYED'])
91
+ if not df.empty:
92
+ c_scaler = scaler.transform(df.values.reshape(1, -1))
93
+
94
+ loan_prediction = model.predict(c_scaler)
95
+
96
+ if loan_prediction[0] == 1:
97
+ loan_diagnose = f"Pengajuan Kartu Kredit Atas Nama {Name} Ditolak"
98
+ else:
99
+ loan_diagnose = f"Pengajuan Kartu Kredit Atas Nama {Name} Diterima"
100
+
101
+ if loan_prediction[0] == 1:
102
+ st.error(loan_diagnose, icon="❌")
103
+ else:
104
+ st.success(loan_diagnose, icon="✅")
105
+ else:
106
+ st.error("Harap isi semua form terlebih dahulu.")