Download app.py from DataWizard9742/CustomerChurnPrediction: direct link, hf CLI and curl.
- Browser
- Download file 2.32 kB
-
https://huggingface.co/spaces/DataWizard9742/CustomerChurnPrediction/resolve/main/app.py
- Command line
-
hf download hf://spaces/DataWizard9742/CustomerChurnPrediction/app.py
-
curl -L -o app.py https://huggingface.co/spaces/DataWizard9742/CustomerChurnPrediction/resolve/main/app.py
2.32 kB
| # importing the libraries | |
| import pickle | |
| import streamlit as st | |
| import pandas as pd | |
| import sklearn | |
| import numpy | |
| # calling our pickle file | |
| model = pickle.load(open("model-3.pkl", "rb")) | |
| # creating a title for website | |
| st.title("Customer Churn Prediction for Banks") | |
| min_max_values = { | |
| 'credit_score': {'min': 350, 'max': 850}, | |
| 'age': {'min': 18, 'max': 92}, | |
| 'tenure': {'min': 0, 'max': 20}, | |
| 'balance': {'min': 0, 'max': 250000}, | |
| 'num_of_products': {'min': 1, 'max': 4}, | |
| 'estimated_salary': {'min': 10000, 'max': 200000} | |
| } | |
| def min_max_scale(value, feature_name): | |
| min_val = min_max_values[feature_name]['min'] | |
| max_val = min_max_values[feature_name]['max'] | |
| return (value - min_val) / (max_val - min_val) | |
| credit_score = min_max_scale( | |
| st.number_input("Credit Score:", min_value=350, max_value=850, help="Enter a value between 350 and 850"), | |
| 'credit_score' | |
| ) | |
| gender = st.number_input("Gender (1 for Male, 0 for Female):", min_value=0, max_value=1) | |
| age = min_max_scale( | |
| st.number_input("Age:", min_value=18, max_value=92), | |
| 'age' | |
| ) | |
| tenure = min_max_scale( | |
| st.number_input("Tenure (years):", min_value=0, max_value=20), | |
| 'tenure' | |
| ) | |
| balance = min_max_scale( | |
| st.number_input("Account Balance:", help="Enter your account balance"), | |
| 'balance' | |
| ) | |
| num_of_products = min_max_scale( | |
| st.number_input("Number of Products:", min_value=1, max_value=4), | |
| 'num_of_products' | |
| ) | |
| has_credit_card = st.number_input("Do you have a Credit Card? (1 for Yes, 0 for No)") | |
| is_active_member = st.number_input("Are you an Active Member? (1 for Yes, 0 for No)") | |
| estimated_salary = min_max_scale( | |
| st.number_input("Estimated Salary:", help="Enter your estimated annual salary"), | |
| 'estimated_salary' | |
| ) | |
| country_options = {"France": 1, "Spain": 2, "Germany": 3} | |
| country = st.radio("Choose your country:", list(country_options.keys())) | |
| country_code = country_options[country] | |
| user_input_scaled = pd.DataFrame([[ | |
| credit_score, gender, age, tenure, balance, num_of_products, | |
| has_credit_card, is_active_member, estimated_salary, country_code | |
| ]]) | |
| if st.button("Predict Churn"): | |
| prediction = model.predict(user_input_scaled)[0] | |
| message = "The customer is most likely to churn." if prediction == 1 else "The customer is not likely to churn." | |
| st.write(message) | |