Spaces:
Sleeping
Sleeping
Download prediction.py from grcvlrn/Deployment: direct link, hf CLI and curl.
- Browser
- Download file 3.12 kB
-
https://huggingface.co/spaces/grcvlrn/Deployment/resolve/main/prediction.py
- Command line
-
hf download hf://spaces/grcvlrn/Deployment/prediction.py
-
curl -L -o prediction.py https://huggingface.co/spaces/grcvlrn/Deployment/resolve/main/prediction.py
3.12 kB
| import streamlit as st | |
| import pandas as pd | |
| import joblib | |
| st.header('Predicting Default Payment') | |
| st.write(""" | |
| For credit card staffs | |
| Use the sidebar to select input features. | |
| """) | |
| def fetch_data(): | |
| df = pd.read_csv('P1G5_Set_1_gracia_valerine.csv') | |
| return df | |
| df = fetch_data() | |
| st.write(df) | |
| st.sidebar.header('User Input Features') | |
| def user_input(): | |
| limit_balance = st.sidebar.selectbox('Limit Balance', df['limit_balance'].unique()) | |
| sex = st.sidebar.selectbox('sex', df['sex'].unique()) | |
| edu = st.sidebar.selectbox('education_level', df['education_level'].unique()) | |
| stat = st.sidebar.selectbox('marital_status', df['marital_status'].unique()) | |
| age = st.sidebar.number_input('age', 0.0, value=58.0) | |
| pay_0 = st.sidebar.number_input('age', 0.0, value=58.0) | |
| pay_2 = st.sidebar.selectbox('pay_0', df['pay_2'].unique()) | |
| pay_3 = st.sidebar.selectbox('pay_2', df['pay_2'].unique()) | |
| pay_4 = st.sidebar.selectbox('pay_3', df['pay_3'].unique()) | |
| pay_5 = st.sidebar.selectbox('pay_4', df['pay_4'].unique()) | |
| pay_6 = st.sidebar.selectbox('pay_5', df['pay_5'].unique()) | |
| pay_6 = st.sidebar.selectbox('pay_6', df['pay_6'].unique()) | |
| bill_amt_1 = st.sidebar.number_input('bill_amt_1', 0.0, value=58000.0) | |
| bill_amt_2 = st.sidebar.number_input('bill_amt_2', 0.0, value=60000.0) | |
| bill_amt_3 = st.sidebar.number_input('bill_amt_3', 0.0, value=100000.0) | |
| bill_amt_4 = st.sidebar.number_input('bill_amt_4', 0.0, value=200.0) | |
| bill_amt_5 = st.sidebar.number_input('bill_amt_5', 0.0, value=580.0) | |
| bill_amt_6 = st.sidebar.number_input('bill_amt_6', 0.0, value=21.0) | |
| pay_amt_1 = st.sidebar.number_input('pay_amt_1', 0.0, value=2000.0) | |
| pay_amt_2 = st.sidebar.number_input('pay_amt_2', 0.0, value=300.0) | |
| pay_amt_3 = st.sidebar.number_input('pay_amt_3', 0.0, value=87000.0) | |
| pay_amt_4 = st.sidebar.number_input('pay_amt_4', 0.0, value=10.0) | |
| pay_amt_5 = st.sidebar.number_input('pay_amt_5', 0.0, value=40.0) | |
| pay_amt_6 = st.sidebar.number_input('pay_amt_6', 0.0, value=5.0) | |
| data = { | |
| 'limit_balance': limit_balance, | |
| 'sex': sex, | |
| 'edu': edu, | |
| 'marital_status': stat, | |
| '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, | |
| } | |
| features = pd.DataFrame(data, index=[0]) | |
| return features | |
| input = user_input() | |
| st.subheader('User Input') | |
| st.write(input) | |
| load_model = joblib.load("model.pkl1") | |
| prediction = load_model.predict(input) | |
| if prediction == 1: | |
| prediction = 'Fail to pay' | |
| else: | |
| prediction = 'Pay' | |
| st.write('Based on user input, the placement model predicted: ') | |
| st.write(prediction) |