Spaces:
Runtime error
Runtime error
Add application file
Browse files- Procfile +1 -0
- Training_Data.csv +10 -0
- Training_Data.pkl +3 -0
- app.py +70 -0
- requirements.txt +6 -0
- setup.sh +13 -0
Procfile
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
web: sh setup.sh && streamlit run app.py
|
Training_Data.csv
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Id,income,age,experience,married,house_ownership,car_ownership,profession,city,state,current_job_years,current_house_years,risk_flag
|
| 2 |
+
1,1303835,23,3,single,rented,no,Mechanical_engineer,Rewa,Madhya_Pradesh,3,13,0
|
| 3 |
+
2,7574516,40,10,single,rented,no,Software_Developer,Parbhani,Maharashtra,9,13,0
|
| 4 |
+
3,3991815,66,4,married,rented,no,Technical_writer,Alappuzha,Kerala,4,10,0
|
| 5 |
+
4,6256451,41,2,single,rented,yes,Software_Developer,Bhubaneswar,Odisha,2,12,1
|
| 6 |
+
5,5768871,47,11,single,rented,no,Civil_servant,Tiruchirappalli[10],Tamil_Nadu,3,14,1
|
| 7 |
+
6,6915937,64,0,single,rented,no,Civil_servant,Jalgaon,Maharashtra,0,12,0
|
| 8 |
+
7,3954973,58,14,married,rented,no,Librarian,Tiruppur,Tamil_Nadu,8,12,0
|
| 9 |
+
8,1706172,33,2,single,rented,no,Economist,Jamnagar,Gujarat,2,14,0
|
| 10 |
+
9,7566849,24,17,single,rented,yes,Flight_attendant,Kota[6],Rajasthan,11,11,0
|
Training_Data.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fdd73a4449456def74f8cd20200b3861bf07451367510ef944199585ea64e73c
|
| 3 |
+
size 7685009
|
app.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pickle
|
| 5 |
+
import base64
|
| 6 |
+
import seaborn as sns
|
| 7 |
+
import matplotlib.pyplot as plt
|
| 8 |
+
|
| 9 |
+
st.write("""
|
| 10 |
+
# Credit Risk Detection App
|
| 11 |
+
|
| 12 |
+
""")
|
| 13 |
+
|
| 14 |
+
url_dataset = f'<a href="Training_Data.csv">Download Dataset CSV File</a>'
|
| 15 |
+
st.markdown(url_dataset, unsafe_allow_html=True)
|
| 16 |
+
|
| 17 |
+
def user_input_features() :
|
| 18 |
+
income = st.sidebar.slider('income', 10310, 9999938)
|
| 19 |
+
age = st.sidebar.slider('age', 21, 79)
|
| 20 |
+
experience = st.sidebar.slider('experience', 0, 20)
|
| 21 |
+
married = st.sidebar.slider ('married', 0, 1)
|
| 22 |
+
house_ownership = st.sidebar.slider ('house_ownership', 0, 2)
|
| 23 |
+
car_ownership = st.sidebar.slider ('car_ownership', 0, 1)
|
| 24 |
+
profession = st.sidebar.slider ('profession', 0, 51)
|
| 25 |
+
current_job_years = st.sidebar.slider('current_job_years', 0, 14)
|
| 26 |
+
current_house_years = st.sidebar.slider('current_house_years', 10, 14)
|
| 27 |
+
|
| 28 |
+
data = {'income':[income],
|
| 29 |
+
'age':[age],
|
| 30 |
+
'experience':[experience],
|
| 31 |
+
'married': [married],
|
| 32 |
+
'house_ownership': [house_ownership],
|
| 33 |
+
'car_ownership': [car_ownership],
|
| 34 |
+
'profession': [profession],
|
| 35 |
+
'current_job_years':[current_job_years],
|
| 36 |
+
'current_house_years':[current_house_years]}
|
| 37 |
+
|
| 38 |
+
features = pd.DataFrame(data)
|
| 39 |
+
return features
|
| 40 |
+
|
| 41 |
+
input_df = user_input_features()
|
| 42 |
+
|
| 43 |
+
credit_raw = pd.read_csv('Training_Data.csv')
|
| 44 |
+
credit_raw.fillna(0, inplace=True)
|
| 45 |
+
credit = credit_raw.drop(columns=['risk_flag'])
|
| 46 |
+
df = pd.concat([input_df, credit],axis=0)
|
| 47 |
+
|
| 48 |
+
df = df[:1] # Selects only the first row (the user input data)
|
| 49 |
+
df.fillna(0, inplace=True)
|
| 50 |
+
|
| 51 |
+
features = ['income','age','experience','married','house_ownership','car_ownership','profession','current_job_years',
|
| 52 |
+
'current_house_years']
|
| 53 |
+
|
| 54 |
+
df = df[features]
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
st.subheader('User Input features')
|
| 58 |
+
st.write(df)
|
| 59 |
+
|
| 60 |
+
load_clf = pickle.load(open('Training_Data.pkl', 'rb'))
|
| 61 |
+
detection = load_clf.predict(df)
|
| 62 |
+
detection_proba = load_clf.predict_proba(df)
|
| 63 |
+
credit_labels = np.array(['Normal', 'Beresiko'])
|
| 64 |
+
st.subheader('Detection')
|
| 65 |
+
#st.write(detection)
|
| 66 |
+
st.write(credit_labels[int(detection)])
|
| 67 |
+
st.subheader('Detection Probability')
|
| 68 |
+
st.write(detection_proba)
|
| 69 |
+
#df_prob = pd.DataFrame(data=detection_proba, index=['Probability'], columns=credit_labels)
|
| 70 |
+
#st.write(df_prob)
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
matplotlib==3.5.2
|
| 2 |
+
numpy==1.23.1
|
| 3 |
+
pandas==1.4.3
|
| 4 |
+
seaborn==0.11.2
|
| 5 |
+
streamlit==1.12.0
|
| 6 |
+
sklearn
|
setup.sh
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
mkdir -p ~/.streamlit/
|
| 2 |
+
|
| 3 |
+
echo "\
|
| 4 |
+
[general]\n\
|
| 5 |
+
email = \"your-email@domain.com\"\n\
|
| 6 |
+
" > ~/.streamlit/credentials.toml
|
| 7 |
+
|
| 8 |
+
echo "\
|
| 9 |
+
[server]\n\
|
| 10 |
+
headless = true\n\
|
| 11 |
+
enableCORS=false\n\
|
| 12 |
+
port = $PORT\n\
|
| 13 |
+
" > ~/.streamlit/config.toml
|