Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions F-DetectoR/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# F-DETECTOR

ML integrated web app to predict the genuinity of transactions by inputting the case details

# LIBRARIES USED
- Scikit-learn
- Pandas
- Numpy
- pylab
- matplotlib

# FRAMEWORKS USED
- FLASK

# HOW TO CONTRIBUTE?
Feel free to suggest your opinions by creating an issue or mail us at gthackers4evri1@gmail.com
Binary file added F-DetectoR/__pycache__/forms.cpython-36.pyc
Binary file not shown.
Binary file added F-DetectoR/__pycache__/run.cpython-36.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions F-DetectoR/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired


class CheckForm(FlaskForm):
Step = StringField('Step: ',validators=[DataRequired()])
Type = StringField('Type of transaction: ',validators=[DataRequired()])
Amount = StringField('Amount of transaction: ',validators=[DataRequired()])
D_name = StringField('Name of Despositor: ',validators=[DataRequired()])
A_bal_before = StringField('Account balance of depositor before transaction: ',validators=[DataRequired()])
A_bal_after = StringField('Account balance of depositor after transaction: ',validators=[DataRequired()])
P_name = StringField('Name of Payee: ',validators=[DataRequired()])
P_bal_before = StringField('Account balance of Payee before transaction: ',validators=[DataRequired()])
P_bal_after = StringField('Account balance of Payee after transaction: ',validators=[DataRequired()])
Submit=SubmitField('Submit')
Binary file added F-DetectoR/model.pkl
Binary file not shown.
82 changes: 82 additions & 0 deletions F-DetectoR/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# from google.colab import drive
# drive.mount('/content/gdrive')

import pandas as pd

import numpy as np
import scipy.optimize as opt
from sklearn import preprocessing
# %matplotlib inline
import matplotlib.pyplot as plt
import pylab as pl


import pickle #Modifications for flask

text = open("./paysim.csv", "r")

#join() method combines all contents of
# csvfile.csv and formed as a string
text = ''.join([i for i in text])

# search and replace the contents
text = text.replace("PAYMENT", "1")
text = text.replace("TRANSFER", "2")
text = text.replace("CASH_IN", "3")
text = text.replace("CASH_OUT", "4")
text = text.replace("DEBIT", "5")
# output.csv is the output file opened in write mode
x = open("./output.csv", "w")

# all the replaced text is written in the output.csv file
x.writelines(text)
x.close()

churn_df = pd.read_csv('./output.csv')

X = np.asarray(churn_df[['step', 'type', 'amount', 'oldbalanceOrg', 'newbalanceOrig',
'oldbalanceDest', 'newbalanceDest']])

y = np.asarray(churn_df['isFraud'])

from sklearn import preprocessing
X = preprocessing.StandardScaler().fit(X).transform(X)

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=4)

from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix
LR = LogisticRegression(C=0.01, solver='liblinear').fit(X_train, y_train)

yhat = LR.predict(X_test)

yhat_prob = LR.predict_proba(X_test)

# from sklearn.metrics import jaccard_similarity_score
# jaccard_similarity_score(y_test, yhat) #it is an output

# step=float(input())
# transtype=float(input())
# amount=float(input())
# nameorig=str(input())
# oldbalanceOrg=float(input())
# newbalanceOrig=float(input())
# namedest=str(input())
# oldbalanceDest=float(input())
# newbalanceDest=float(input())

# Z = [[step, transtype, amount, oldbalanceOrg, newbalanceOrig, oldbalanceDest, newbalanceDest]]


from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix
LR = LogisticRegression(C=0.01, solver='liblinear').fit(X_train, y_train)

pickle.dump(LR, open('model.pkl', 'wb')) #Flask modifications

model = pickle.load(open('model.pkl', 'rb'))


yhat = LR.predict(Z)

27 changes: 27 additions & 0 deletions F-DetectoR/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
beautifulsoup4==4.9.3
click==7.1.2
cycler==0.10.0
Flask==1.1.2
Flask-WTF==0.14.3
google==3.0.0
itsdangerous==1.1.0
Jinja2==2.11.2
joblib==1.0.0
kiwisolver==1.3.1
MarkupSafe==1.1.1
matplotlib==3.3.3
numpy==1.19.4
pandas==1.1.5
Pillow==8.0.1
pyparsing==2.4.7
python-dateutil==2.8.1
pytz==2020.4
scikit-learn==0.23.2
scipy==1.5.4
six==1.15.0
sklearn==0.0
soupsieve==2.1
SQLAlchemy==1.3.22
threadpoolctl==2.1.0
Werkzeug==1.0.1
WTForms==2.3.3
58 changes: 58 additions & 0 deletions F-DetectoR/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from flask import Flask, render_template, url_for, redirect, request
import numpy as np
import pickle
from forms import CheckForm


app = Flask(__name__)
app.config['SECRET_KEY']='GTHACKERS'

model = pickle.load(open('model.pkl', 'rb'))

@app.route('/')
def home():
return render_template('GT home.html')


@app.route('/about')
def about():
return render_template('about.html')


@app.route('/contact')
def contact():
return render_template('contact.html')

@app.route('/predict',methods=['GET','POST'])
def predict():
# int_features = [1, 3, 565235956.44242, 13959898.5346, 5464.5434, 21545.54534354, 564.4323434]
form = CheckForm()

if form.is_submitted():
result = request.form.values()

a = list(result)
a.remove('Submit')
a.remove(form.D_name.data)
a.remove(form.P_name.data)


a=[int(x) for x in a]



final_features = [np.array(a)]


prediction=model.predict(final_features)
return render_template('answer.html',prediction=prediction)

# final_features = [np.array(int_features)]
# prediction = model.predict(final_features)

return render_template('formsection.html', form=form)



if __name__ == '__main__':
app.run(debug=True)
Loading