Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pickle | |
| import numpy as np | |
| import joblib | |
| # Load the trained model | |
| #model = pickle.load(open('credit_score.pkl', 'rb')) | |
| model = joblib.load('credit_score.joblib') | |
| # Define the Streamlit app | |
| st.title("Credit Score Prediction") | |
| # Get user input | |
| annual_income = st.number_input("Annual Income", min_value=0,max_value=100000, step=100) | |
| monthly_salary = st.number_input("Monthly In-hand Salary", min_value=0,max_value=5000, step=100.0) | |
| num_bank_accounts = st.number_input("Number of Bank Accounts", min_value=0, step=1) | |
| num_credit_cards = st.number_input("Number of Credit Cards", min_value=0, step=1) | |
| interest_rate = st.number_input("Interest Rate (%)", min_value=0.0, max_value=30.0, step=1) | |
| num_loans = st.number_input("Number of Loans", min_value=0, max_value=10,step=1) | |
| avg_days_delayed = st.number_input("Average Number of Days Delayed", min_value=0.0, step=1.0) | |
| num_delayed_payments = st.number_input("Number of Delayed Payments", min_value=0, step=1) | |
| credit_mix = st.selectbox("Credit Mix", ["Bad", "Standard", "Good"]) | |
| outstanding_debt = st.number_input("Outstanding Debt", min_value=0.0, step=100.0) | |
| credit_history_age = st.number_input("Credit History Age (Years)", min_value=0.0, step=1.0) | |
| monthly_balance = st.number_input("Monthly Balance", min_value=0.0, step=100.0) | |
| # Convert user input to a numpy array | |
| features = np.array([[annual_income, monthly_salary, num_bank_accounts, num_credit_cards, | |
| interest_rate, num_loans, avg_days_delayed, num_delayed_payments, | |
| credit_mix.index(), outstanding_debt, credit_history_age, monthly_balance]]) | |
| # Make the prediction | |
| class_names = ['Bad', 'Standard', 'Good'] | |
| prediction = class_names[int(model.predict(features)[0])] | |
| # Display the prediction | |
| if prediction == 'Good': | |
| st.success(f"Predicted Credit Score: {prediction} π") | |
| elif prediction == 'Standard': | |
| st.warning(f"Predicted Credit Score: {prediction} π€") | |
| else: | |
| st.error(f"Predicted Credit Score: {prediction} π") |