Coder Social home page Coder Social logo

devinaa1604 / credit_risk_analysis_using_classification Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 17.38 MB

This project aims to predict credit risk using various ensemble machine learning techniques. I have also tried to handle imbalance by using various sampling methods.

Jupyter Notebook 100.00%
logistic-regression imbalanced-learning balanced-accuracy-scores imbalance-classification smote-sampling cluster-centroids smoteenn ensemble-learning

credit_risk_analysis_using_classification's Introduction

Credit Risk Using Machine Leaning

Credit Risk

Background

This project aims to help the investors mitigate risk by predicting credit risk with machine learning techniques.

I have built and evaluated several machine learning models to predict credit risk using data would typically come from peer-to-peer lending services. Credit risk is an inherently imbalanced classification problem (the number of good loans is much larger than the number of at-risk loans), so I have employed different techniques for training and evaluating models with imbalanced classes. I have used the imbalanced-learn and Scikit-learn libraries to build and evaluate models using the two following techniques:

  1. Resampling
  2. Ensemble Learning

Resampling

Used the imbalanced learn library to resample the LendingClub data and built and evaluated logistic regression classifiers using the resampled data.

To begin:

  1. Read the CSV into a DataFrame.

  2. Split the data into Training and Testing sets.

  3. Scaled the training and testing data using the StandardScaler from sklearn.preprocessing.

  4. Used the provided code to run a Simple Logistic Regression:

    • Fit the logistic regression classifier.
    • Calculate the balanced accuracy score.
    • Display the confusion matrix.
    • Print the imbalanced classification report.

Next:

  1. Oversample the data using the Naive Random Oversampler and SMOTE algorithms.

  2. Undersample the data using the Cluster Centroids algorithm.

  3. Over- and undersample using a combination SMOTEENN algorithm.

For each of the above, I have:

  1. Trained a logistic regression classifier from sklearn.linear_model using the resampled data.

  2. Calculated the balanced accuracy score from sklearn.metrics.

  3. Displayed the confusion matrix from sklearn.metrics.

  4. Printed the imbalanced classification report from imblearn.metrics.

I have used this to answer the following questions:

  • Which model had the best balanced accuracy score?

Naive Random Oversampling, SMOTE Oversampling and SMOTEEN have the same and the highest balanced accuracy score

  • Which model had the best recall score?

All the models have the same recall score of 0.99

  • Which model had the best geometric mean score?

All the models have the same geometric mean score of 0.99

Ensemble Learning

Here, first I train and compare two different ensemble classifiers to predict loan risk and evaluate each model. I have used the Balanced Random Forest Classifier and the Easy Ensemble Classifier.

To begin:

  1. Read the data into a DataFrame using the provided starter code.

  2. Split the data into training and testing sets.

  3. Scale the training and testing data using the StandardScaler from sklearn.preprocessing.

Next:

  1. Train the model using the quarterly data from LendingClub provided in the Resource folder.

  2. Calculate the balanced accuracy score from sklearn.metrics.

  3. Display the confusion matrix from sklearn.metrics.

  4. Generate a classification report using the imbalanced_classification_report from imbalanced learn.

  5. For the balanced random forest classifier only, print the feature importance sorted in descending order (most important feature to least important) along with the feature score.

I have used this to answer the following questions:

  • Which model had the best balanced accuracy score?

Easy ensemble classifier

  • Which model had the best recall score?

Easy ensemble classifier

  • Which model had the best geometric mean score?

Easy ensemble classifier

  • What are the top three features?

Total Rec Prncp, Total Pymnt, Total Pyment Inv

credit_risk_analysis_using_classification's People

Contributors

devinaa1604 avatar

Stargazers

 avatar

Watchers

 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.