File size: 2,283 Bytes
a4b0383
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
from sklearn.pipeline import Pipeline 
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import StandardScaler,OneHotEncoder
import streamlit as st
import joblib

df=pd.read_csv('PS_20174392719_1491204439457_log.csv')
model = joblib.load('best_model.pkl')

preprocessor=ColumnTransformer(
    transformers=[
        ('num',StandardScaler(),['step','amount','oldbalanceOrg','newbalanceOrig','oldbalanceDest','newbalanceDest']),
        ('cat',OneHotEncoder(),['type'])
    ]
)
pipeline=Pipeline(steps=[('preprocessor',preprocessor),('regressor',model)])
pipeline.fit(df[['step','amount','oldbalanceOrg','newbalanceOrig','oldbalanceDest','newbalanceDest','type']],df[['isFraud']])
def price_pred(step,amount,oldbalanceOrg,newbalanceOrig,oldbalanceDest,newbalanceDest,type):
    input_data=pd.DataFrame({
        'step':[step],
        'amount':[amount],
        'oldbalanceOrg':[oldbalanceOrg],
        'newbalanceOrig':[newbalanceOrig],
        'oldbalanceDest':[oldbalanceDest],
        'newbalanceDest':[newbalanceDest],
        'type':[type]
    })
    prediction=pipeline.predict(input_data)[0]
    return prediction

def main():
    st.title('Fraud Detection')
    st.write('Enter process detail and predict fraud or not')

    
    type=st.selectbox('Type',df['type'].unique())
    amount=st.number_input('Amount',int(df['amount'].min()),int(df['amount'].max()))
    oldbalanceOrg=st.number_input('oldbalanceOrg',int(df['oldbalanceOrg'].min()),int(df['oldbalanceOrg'].max()))
    newbalanceOrig=st.number_input('newbalanceOrig',int(df['newbalanceOrig'].min()),int(df['newbalanceOrig'].max()))
    oldbalanceDest=st.number_input('oldbalanceDest',int(df['oldbalanceDest'].min()),int(df['oldbalanceDest'].max()))
    newbalanceDest=st.number_input('newbalanceDest',int(df['newbalanceDest'].min()),int(df['newbalanceDest'].max()))
    step=st.number_input('step',int(df['step'].min()),int(df['step'].max()))


    if st.button('Predict'):
        prediction=price_pred(step,amount,oldbalanceOrg,newbalanceOrig,oldbalanceDest,newbalanceDest,type)
        if prediction==1:
            st.write(f'The Proces is FRAUD')
        elif prediction==0:
            st.write(f'The Proces is NOT FRAUD')
        
if __name__=='__main__':
    main()