Upload 3 files
Browse files- app.py +54 -0
- best_model.pkl +3 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
from sklearn.pipeline import Pipeline
|
| 3 |
+
from sklearn.compose import ColumnTransformer
|
| 4 |
+
from sklearn.preprocessing import StandardScaler,OneHotEncoder
|
| 5 |
+
import streamlit as st
|
| 6 |
+
import joblib
|
| 7 |
+
|
| 8 |
+
df=pd.read_csv('PS_20174392719_1491204439457_log.csv')
|
| 9 |
+
model = joblib.load('best_model.pkl')
|
| 10 |
+
|
| 11 |
+
preprocessor=ColumnTransformer(
|
| 12 |
+
transformers=[
|
| 13 |
+
('num',StandardScaler(),['step','amount','oldbalanceOrg','newbalanceOrig','oldbalanceDest','newbalanceDest']),
|
| 14 |
+
('cat',OneHotEncoder(),['type'])
|
| 15 |
+
]
|
| 16 |
+
)
|
| 17 |
+
pipeline=Pipeline(steps=[('preprocessor',preprocessor),('regressor',model)])
|
| 18 |
+
pipeline.fit(df[['step','amount','oldbalanceOrg','newbalanceOrig','oldbalanceDest','newbalanceDest','type']],df[['isFraud']])
|
| 19 |
+
def price_pred(step,amount,oldbalanceOrg,newbalanceOrig,oldbalanceDest,newbalanceDest,type):
|
| 20 |
+
input_data=pd.DataFrame({
|
| 21 |
+
'step':[step],
|
| 22 |
+
'amount':[amount],
|
| 23 |
+
'oldbalanceOrg':[oldbalanceOrg],
|
| 24 |
+
'newbalanceOrig':[newbalanceOrig],
|
| 25 |
+
'oldbalanceDest':[oldbalanceDest],
|
| 26 |
+
'newbalanceDest':[newbalanceDest],
|
| 27 |
+
'type':[type]
|
| 28 |
+
})
|
| 29 |
+
prediction=pipeline.predict(input_data)[0]
|
| 30 |
+
return prediction
|
| 31 |
+
|
| 32 |
+
def main():
|
| 33 |
+
st.title('Fraud Detection')
|
| 34 |
+
st.write('Enter process detail and predict fraud or not')
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
type=st.selectbox('Type',df['type'].unique())
|
| 38 |
+
amount=st.number_input('Amount',int(df['amount'].min()),int(df['amount'].max()))
|
| 39 |
+
oldbalanceOrg=st.number_input('oldbalanceOrg',int(df['oldbalanceOrg'].min()),int(df['oldbalanceOrg'].max()))
|
| 40 |
+
newbalanceOrig=st.number_input('newbalanceOrig',int(df['newbalanceOrig'].min()),int(df['newbalanceOrig'].max()))
|
| 41 |
+
oldbalanceDest=st.number_input('oldbalanceDest',int(df['oldbalanceDest'].min()),int(df['oldbalanceDest'].max()))
|
| 42 |
+
newbalanceDest=st.number_input('newbalanceDest',int(df['newbalanceDest'].min()),int(df['newbalanceDest'].max()))
|
| 43 |
+
step=st.number_input('step',int(df['step'].min()),int(df['step'].max()))
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
if st.button('Predict'):
|
| 47 |
+
prediction=price_pred(step,amount,oldbalanceOrg,newbalanceOrig,oldbalanceDest,newbalanceDest,type)
|
| 48 |
+
if prediction==1:
|
| 49 |
+
st.write(f'The Proces is FRAUD')
|
| 50 |
+
elif prediction==0:
|
| 51 |
+
st.write(f'The Proces is NOT FRAUD')
|
| 52 |
+
|
| 53 |
+
if __name__=='__main__':
|
| 54 |
+
main()
|
best_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:30d724a23d06ae64ea913b62139bba3fc63174846056e2319f13f3f38e114943
|
| 3 |
+
size 27838713
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
joblib
|
| 2 |
+
scikit-learn
|
| 3 |
+
streamlit
|