File size: 5,403 Bytes
548c9e5
 
cc8fc58
 
 
 
548c9e5
cc8fc58
 
 
318466b
cc8fc58
 
318466b
cc8fc58
 
318466b
cc8fc58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4532fe3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cc8fc58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Contents of `app2.py`
import streamlit as st
import pandas as pd 
import joblib
import json

def app():
    st.title('Make Predictions')
    
    # load the model
    with open('model.pkl', 'rb') as file_1:
        model = joblib.load(file_1)
        
    with open('column.txt', 'r') as file_2:
        selected_columns = json.load(file_2)
        
    with open('scaler.pkl', 'rb') as file_3:
        scaler = joblib.load(file_3)
    
    st.title("Data Input Options")

    option = st.selectbox(
        "How would you like to input the data?",
        ("Upload a CSV file", "Manually input data")
    )

    if option == "Upload a CSV file":
        uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
        if uploaded_file is not None:
            df = pd.read_csv(uploaded_file)
            st.write("Data Preview:")
            st.write(df)
            
            # Select only the columns for modeling
            data_inference_num = df[selected_columns]

            # Scaling the data
            data_inference_scaled = scaler.transform(data_inference_num)

            # Create new dataframe
            data_inference_final = pd.DataFrame(data_inference_scaled, columns=selected_columns)

            # Predict the defaulter
            predicted_defaulter = model.predict(data_inference_final)

            # Show result
            st.write("Predicted Defaulter Status:")
            st.write(predicted_defaulter)
            
    elif option == "Manually input data":
        st.write("Enter your data:")
        # Define empty lists for each attribute
        limit_balance = []
        sex = []
        education_level = []
        marital_status = []
        age = []
        pay_0 = []
        pay_2 = []
        pay_3 = []
        pay_4 = []
        pay_5 = []
        pay_6 = []
        bill_amt_1 = []
        bill_amt_2 = []
        bill_amt_3 = []
        bill_amt_4 = []
        bill_amt_5 = []
        bill_amt_6 = []
        pay_amt_1 = []
        pay_amt_2 = []
        pay_amt_3 = []
        pay_amt_4 = []
        pay_amt_5 = []
        pay_amt_6 = []
        
        limit_balance.append(st.number_input("Limit Balance", min_value=0))
        sex.append(st.selectbox("Sex", [1, 2]))
        education_level.append(st.selectbox("Education Level", [0, 1, 2, 3]))
        marital_status.append(st.selectbox("Marital Status", [0, 1, 2 , 3]))
        age.append(st.number_input("Age", min_value=0))
        pay_0.append(st.number_input("Pay 0", min_value=-2, max_value=12))
        pay_2.append(st.number_input("Pay 2", min_value=-2, max_value=12))
        pay_3.append(st.number_input("Pay 3", min_value=-2, max_value=12))
        pay_4.append(st.number_input("Pay 4", min_value=-2, max_value=12))
        pay_5.append(st.number_input("Pay 5", min_value=-2, max_value=12))
        pay_6.append(st.number_input("Pay 6", min_value=-2, max_value=12))
        bill_amt_1.append(st.number_input("Bill Amount 1", min_value=0))
        bill_amt_2.append(st.number_input("Bill Amount 2", min_value=0))
        bill_amt_3.append(st.number_input("Bill Amount 3", min_value=0))
        bill_amt_4.append(st.number_input("Bill Amount 4", min_value=0))
        bill_amt_5.append(st.number_input("Bill Amount 5", min_value=0))
        bill_amt_6.append(st.number_input("Bill Amount 6", min_value=0))
        pay_amt_1.append(st.number_input("Pay Amount 1", min_value=0))
        pay_amt_2.append(st.number_input("Pay Amount 2", min_value=0))
        pay_amt_3.append(st.number_input("Pay Amount 3", min_value=0))
        pay_amt_4.append(st.number_input("Pay Amount 4", min_value=0))
        pay_amt_5.append(st.number_input("Pay Amount 5", min_value=0))
        pay_amt_6.append(st.number_input("Pay Amount 6", min_value=0))

        if st.button("Submit"):
            data = {
                'limit_balance': limit_balance,
                'sex': sex,
                'education_level': education_level,
                'marital_status': marital_status,
                'age': age,
                'pay_0': pay_0,
                'pay_2': pay_2,
                'pay_3': pay_3,
                'pay_4': pay_4,
                'pay_5': pay_5,
                'pay_6': pay_6,
                'bill_amt_1': bill_amt_1,
                'bill_amt_2': bill_amt_2,
                'bill_amt_3': bill_amt_3,
                'bill_amt_4': bill_amt_4,
                'bill_amt_5': bill_amt_5,
                'bill_amt_6': bill_amt_6,
                'pay_amt_1': pay_amt_1,
                'pay_amt_2': pay_amt_2,
                'pay_amt_3': pay_amt_3,
                'pay_amt_4': pay_amt_4,
                'pay_amt_5': pay_amt_5,
                'pay_amt_6': pay_amt_6
            }
            df = pd.DataFrame(data)
            st.write("Data Preview:")
            st.write(df)
            
            # Select only the columns for modeling
            data_inference_num = df[selected_columns]

            # Scaling the data
            data_inference_scaled = scaler.transform(data_inference_num)

            # Create new dataframe
            data_inference_final = pd.DataFrame(data_inference_scaled, columns=selected_columns)

            # Predict the defaulter
            predicted_defaulter = model.predict(data_inference_final)

            # Show result
            st.write("Predicted Defaulter Status:")
            st.write(predicted_defaulter)