File size: 2,016 Bytes
b0f3a2d
 
17c19e6
b0f3a2d
17c19e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import numpy as np
import tensorflow as tf
from sklearn.preprocessing import StandardScaler, LabelEncoder

# Load the model
model = tf.keras.models.load_model("banking_model.keras")

# Function to preprocess input data
def preprocess_input(input_data, label_encoders, scaler):
    # Convert input data to DataFrame
    input_df = pd.DataFrame([input_data])
    
    # Encode categorical variables
    for col in label_encoders:
        input_df[col] = label_encoders[col].transform(input_df[col])
    
    # Scale numerical variables
    numerical_columns = input_df.select_dtypes(include=["int64", "float64"]).columns
    input_df[numerical_columns] = scaler.transform(input_df[numerical_columns])
    
    return input_df

# Streamlit app
def main():
    st.title("Banking Stage Classification")
    
    # Input fields
    st.sidebar.header("User Input Features")
    
    # Example feature inputs, adjust according to your actual features
    credit_expiration = st.sidebar.number_input("Credit Expiration", min_value=0, value=0)
    dpd = st.sidebar.number_input("DPD", min_value=0, value=0)
    feature1 = st.sidebar.selectbox("Feature 1", options=["Yes", "No"])
    feature2 = st.sidebar.selectbox("Feature 2", options=["Yes", "No"])
    stage_last_month = st.sidebar.selectbox("Stage As Last Month", options=[1, 2, 3])
    
    # Prepare input data
    input_data = {
        'Credit Expiration': credit_expiration,
        'DPD': dpd,
        'Feature 1': feature1,
        'Feature 2': feature2,
        'Stage As Last Month': stage_last_month
    }
    
    # Preprocess the input
    processed_input = preprocess_input(input_data, label_encoders, scaler)
    
    # Make prediction
    if st.sidebar.button("Predict"):
        prediction = model.predict(processed_input)
        predicted_stage = np.argmax(prediction, axis=1) + 1  # Adjust if necessary
        st.success(f"Predicted Current Stage: {predicted_stage[0]}")

if __name__ == "__main__":
    main()