Churn_app / src /streamlit_app.py
atdokmeci's picture
Update src/streamlit_app.py
734f09c verified
# import streamlit as st
# from tensorflow import keras
# st.title('Credit Application Customer Prediction')
# model = keras.models.load_model('src/churn_model.h5')
# CreditScore=st.number_input('CreditScore', 1,10)
# Age=st.number_input('Age', 1,100)
# NumOfProducts=st.number_input('Number of Products', 1,100)
# if st.button('Tahmin et'):
# tahmin=model.predict([[CreditScore,Age,NumOfProducts]])
# tahmin=round(tahmin[0][0],2)
# st.success(f'YZ Has Exited the Bank: ${tahmin}')
# import streamlit as st
# import numpy as np
# from tensorflow.keras.models import load_model
# st.title('Credit Application Customer Prediction')
# # Load the model, ensuring the file path is correct
# try:
# model = load_model('src/churn_model.h5')
# except Exception as e:
# st.error(f"Error loading model: {e}")
# CreditScore = st.number_input('CreditScore', 1, 850)
# Age = st.number_input('Age', 1, 80)
# NumOfProducts = st.number_input('Number of Products', 1, 3)
# if st.button('Tahmin et'):
# input_data = np.array([[float(CreditScore), float(Age), float(NumOfProducts)]], dtype=np.float32)
# try:
# tahmin = model.predict(input_data)
# tahmin = round(tahmin[0][0], 2)
# st.success(f'YZ Has Exited the Bank: ${tahmin}')
# except Exception as e:
# st.error(f"Error making prediction: {e}")
import streamlit as st
import numpy as np
from tensorflow.keras.models import load_model
st.title('Credit Application Customer Prediction')
# Load the model
try:
model = load_model('src/churn_model.h5')
except Exception as e:
st.error(f"Error loading model: {e}")
# Input fields based on df1 columns (after encoding and feature engineering)
CreditScore = st.number_input('Credit Score', min_value=300, max_value=850)
Gender = st.selectbox('Gender', ['Male', 'Female'])
Age = st.number_input('Age', min_value=18, max_value=100)
Tenure = st.number_input('Tenure (Years)', min_value=0, max_value=10)
Balance = st.number_input('Balance', min_value=0.0)
NumOfProducts = st.number_input('Number of Products', min_value=1, max_value=4)
HasCrCard = st.selectbox('Has Credit Card', [0, 1])
IsActiveMember = st.selectbox('Is Active Member', [0, 1])
EstimatedSalary = st.number_input('Estimated Salary', min_value=0.0)
BalanceSalaryRatio = Balance / EstimatedSalary if EstimatedSalary > 0 else 0
TenureByAge = Tenure / Age if Age > 0 else 0
# One-hot encoded Geography fields
Geography_France = st.selectbox('Geography: France', [0, 1])
Geography_Spain = st.selectbox('Geography: Spain', [0, 1])
Geography_Germany = st.selectbox('Geography: Germany', [0, 1])
if st.button('Tahmin et'):
# Input order must match df1 columns used for model training
input_data = np.array([[
CreditScore,
1 if Gender == 'Male' else 0,
Age,
Tenure,
Balance,
NumOfProducts,
HasCrCard,
IsActiveMember,
EstimatedSalary,
BalanceSalaryRatio,
TenureByAge,
Geography_France,
Geography_Germany,
Geography_Spain
]], dtype=np.float32)
try:
tahmin = model.predict(input_data)
tahmin = round(tahmin[0][0], 2)
st.success(f'Prediction: {tahmin}')
except Exception as e:
st.error(f"Error making prediction: {e}")