Spaces:
Build error
Build error
File size: 2,387 Bytes
9e6687b 9e9b48d 9e6687b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import streamlit as st
import pandas as pd
import numpy as np
import pickle
import base64
import seaborn as sns
import matplotlib.pyplot as plt
import symbol
st.write("""
# Detection Fraud Credit Card
Kartu kredit adalah sebuah alat pembayaran menggunakan kartu yang berfungsi sebagai pengganti uang tunai.
""")
url_dataset = f'<a href="card.csv">Download Dataset CSV File</a>'
st.markdown(url_dataset, unsafe_allow_html=True)
def user_input_features() :
distance_from_home = st.sidebar.slider('distance_from_home', 0.004874, 10632.723672)
distance_from_last_transaction = st.sidebar.slider('distance_from_last_transaction', 0.000118, 11851.104565)
ratio_to_median_purchase_price = st.sidebar.slider('ratio_to_median_purchase_price', 0.004399, 267.802942)
repeat_retailer = st.sidebar.slider('repeat_retailer', 0.0, 1.0)
used_chip = st.sidebar.slider('used_chip', 0.0, 1.0)
used_pin_number = st.sidebar.slider('used_pin_number ', 0.0, 1.0)
online_order = st.sidebar.slider('online_order ', 0.0, 1.0)
data = {
'distance_from_home':[distance_from_home],
'distance_from_last_transaction':[distance_from_last_transaction],
'ratio_to_median_purchase_price':[ratio_to_median_purchase_price],
'repeat_retailer':[repeat_retailer],
'used_pin_number':[used_pin_number],
'online_order':[online_order],
'used_chip':[used_chip]
}
features = pd.DataFrame(data)
return features
input_df = user_input_features()
card_raw = pd.read_csv('card.csv')
card_raw.fillna(0, inplace=True)
card = card_raw.drop(columns=['fraud'])
df = pd.concat([input_df, card],axis=0)
df = df[:1] # Selects only the first row (the user input data)
df.fillna(0, inplace=True)
features = ['distance_from_home', 'distance_from_last_transaction',
'ratio_to_median_purchase_price', 'repeat_retailer', 'used_chip',
'used_pin_number', 'online_order']
df = df[features]
st.subheader('User Input features')
st.write(df)
load_clf = pickle.load(open('card_clf.pkl', 'rb'))
detection = load_clf.predict(df)
if(detection > 0) :
detection = 1
detection_proba = load_clf.predict_proba(df)
knee_labels = np.array(['Normal','Penipuan'])
st.subheader('Detection')
st.write(knee_labels[detection])
st.subheader('Detection Probability')
df_prob = pd.DataFrame(data=detection_proba, index=['Probability'], columns=knee_labels)
st.write(df_prob) |