Mortgages, student and auto loans, and debt consolidation are just a few examples of credit and loans that people seek online. Peer-to-peer lending services such as Loans Canada and Mogo let investors loan people money without using a bank. However, because investors always want to mitigate risk, a client has asked that you help them predict credit risk with machine learning techniques.
Built and evaluated several machine learning models to predict credit risk using data typically seen 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 you will need to employ different techniques for training and evaluating models with imbalanced classes. Use the imbalanced-learn and Scikit-learn libraries to build and evaluate models using the two following techniques:
Used the imbalanced learn library to resample the LendingClub data and built and evaluated logistic regression classifiers using the resampled data.
-
Read the CSV into a DataFrame.
-
Split the data into Training and Testing sets.
-
Scaled the training and testing data using the
StandardScaler
fromsklearn.preprocessing
. -
Solved for Simple Logistic Regression:
- Fitted the
logistic regression classifier
. - Calculated the
balanced accuracy score
. - Displayed the
confusion matrix
. - Printed the
imbalanced classification report
.
- Fitted the
-
Oversampled the data using the
Naive Random Oversampler
andSMOTE
algorithms. -
Undersampled the data using the
Cluster Centroids
algorithm. -
Over- and undersample using a combination
SMOTEENN
algorithm. -
For each of the above:
a. Trained a logistic regression classifier
from sklearn.linear_model
using the resampled data.
b. Calculated the balanced accuracy score
from sklearn.metrics
.
c. Displayed the confusion matrix
from sklearn.metrics
.
d. Printed the imbalanced classification report
from imblearn.metrics
.
In this section, trained and compared two different ensemble classifiers to predict loan risk and evaluate each model. used the Balanced Random Forest Classifier and the Easy Ensemble Classifier.
-
Read the data into a DataFrame using the provided starter code.
-
Split the data into training and testing sets.
-
Scaled the training and testing data using the
StandardScaler
fromsklearn.preprocessing
.
Then, completed the following steps for each model:
-
Trained the modeled using the quarterly data from LendingClub provided in the
Resource
folder. -
Calculate the balanced accuracy score from
sklearn.metrics
. -
Displayed the confusion matrix from
sklearn.metrics
. -
Generated a classification report using the
imbalanced_classification_report
from imbalanced learn. -
For the balanced random forest classifier only, printed the feature importance sorted in descending order (most important feature to least important) along with the feature score.