Giter Site home page Giter Site logo

ut-final-project's Introduction

UT-Final-Project

Training a machine learning model to identify whether particular transactions are fraud.

Attention!

Download csv from https://www.kaggle.com/ntnu-testimon/paysim1 and place csv file in "data" folder. Title file "transaction.csv"

Make sure XGBClassifier is installed: conda install -c conda-forge xgboost

Also, you may have to revert matplotlib library back to 1.5:

  • pip uninstall matplotlib

  • pip install matplotlib==1.3.1

Introduction

The primary library that I have chosen to use is the XGBoost library, which I believe is somehow connected to Sklearn. More specifically, the type of machine learning that is functioning is a combonation between logistical regression and gradiant boosting trees. Logistical regression is optimal for binary factors such as in this case of whether a transaction can be classified as fraud or not.

Usability

So after ensuring that xgboost is installed, open the jupyter notebook.

It will be a very simple file since I have been practicing "compartimentalizing" the code into seperate files that can be called upon when needed. Just run the whole file or each cell individually. Fair warning, it may take upwards of five minuits to calculate everything involved.

Results of the code

The main two parts of the output are as follows:

The XGB Decision Tree Metrics, which shows key statistics on the performance of the model, such as the Accuracy, Log Loss, and Error.

The graphical representation of the precision recall curve which the tradeoff between precision and recall are shown. Precision is true positives over true positives plus false positives, while recall is true positives over true positives plus false negatives.

If for some reason there are no error messages and the graph does not show then create a cell above with this:

from IPython.core.interactiveshell import InteractiveShell InteractiveShell.ast_node_interactivity = "all"

Explanation of the code

The jupyter file starts out by running "prep". This is a file that takes in the "transactions.csv" and cleans it so it is ready for processing.

Next "training_testing" is ran which calls upon the "get_data" function in "prep" to collect the x and y needed

Spliting the data into four different groups called trainX, testX, trainY, and testY is then fitted into the xgbclassifier.

The probability predictions and regular predictions are generated and used to be the basis of three different metrics which I got from https://scikit-learn.org/stable/modules/classes.html

Then the "pickle" library is used to save the model into "models" which can be called upon later for prediction.

A really cool visulaization is created with the next section of code, which I found on https://scikit-learn.org/stable/auto_examples/model_selection/plot_precision_recall.html#sphx-glr-auto-examples-model-selection-plot-precision-recall-py

To read more on this: https://stats.stackexchange.com/questions/350134/how-does-gradient-boosting-calculate-probability-estimates

There is some code in "training_testing.py" which I was experimeting with, but could not figure out how to function. Its in there so I can go back later and tweak.

Technologies used

  • Python
  • Jupyter Notebook
  • Pandas
  • Numpy
  • SciKit-Learn
  • XGBoost
  • Pickle
  • Matplotlib
  • Inspect
  • Graphviz (not used)

ut-final-project's People

Contributors

blakerosenhagen avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.