Use various techniques to train and evaluate a model based on loan risk. I’ll use a dataset of historical lending activity from a peer-to-peer lending services company to build a model that can identify the creditworthiness of borrowers.
Using various techniques train and evaluate a model based on loan risk.
Requirements for the software and other tools to build, test and push
The instructions for this Challenge are divided into the following subsections:
- Split the Data into Training and Testing Sets
- Create a Logistic Regression Model with the Original Data
- Write a Credit Risk Analysis Report
Open the starter code notebook and use it to complete the following steps:
- Read the lending_data.csv data from the Resources folder into a Pandas DataFrame.
- Create the labels set (y) from the “loan_status” column, and then create the features (X) DataFrame from the remaining columns.
- NOTE
- A value of 0 in the “loan_status” column means that the loan is healthy. A value of 1 means that the loan has a high risk of defaulting.
- Split the data into training and testing datasets by using train_test_split.
Use your knowledge of logistic regression to complete the following steps:
-
Fit a logistic regression model by using the training data (X_train and y_train).
-
Save the predictions for the testing data labels by using the testing feature data (X_test) and the fitted model.
-
Evaluate the model’s performance by doing the following:
-
Generate a confusion matrix.
-
Print the classification report.
-
-
Answer the following question: How well does the logistic regression model predict both the 0 (healthy loan) and 1 (high-risk loan) labels?
Write a brief report that includes a summary and analysis of the performance of the machine learning models that you used in this homework.
Structure your report by using the report template that Starter_Code.zip includes, ensuring that it contains the following:
-
An overview of the analysis: Explain the purpose of this analysis.
-
The results: Using a bulleted list, describe the accuracy score, the precision score, and recall score of the machine learning model.
-
A summary: Summarize the results from the machine learning model. Include your justification for recommending the model for use by the company. If you don’t recommend the model, justify your reasoning.
-
The analysis's goal is to develop and assess a loan risk-based model. Using a peer-to-peer lending services company's historical lending activity dataset, I developed a model that can determine a borrower's creditworthiness based on loan_status, the accuracy for healthy and high risk loans.
-
The following were the contents of the dataset : loan size, interest rate, borrower income, debt to income, number of accounts, derogatory marks, total debt and loan status.
-
The loan status, represented by variable y, is categorized as either 0 or 1, where a loan is considered healthy if its value is 0 and it is considered high-risk of default if its value is 1. While everything else in the dataset falls under variable x.
-
The stages of the machine learning process I went through as part of this analysis:
- Data Collecting and Preparing
- Model Selection (Logistic Regression Model with the Original Data or Logistic Regression Model with Resampled Training Data)
- Model Training
- Model Prediction
- Model Utilization - Evaluate the model’s performance through:
- Calculate the accuracy score of the model.
- Generate a confusion matrix.
- Printing the classification report.
-
The accuracy score, confusion matrix, and classification report where all used as the basis for evaluating the model's performance.
Using bulleted lists, describe the balanced accuracy scores and the precision and recall scores of all machine learning models.
-
Machine Learning Model 1:
-
Logistic Regression: Accuracy: 0.9520479254722232 (95.2 %)
-
Precision: 0 ---> 1.00 , 1 ---> 0.85
-
Recall Scores: 0 ---> 0.99 , 1 ---> 0.91
-
-
Machine Learning Model 2:
-
Logistic Regression: Accuracy: 0.9949885376126246 (99.4 %)
-
Precision: 0 ---> 1.00 , 1 ---> 0.99
-
Recall Scores: 0 ---> 0.99 , 1 ---> 1.00
-
-
My recommendation is to choose Model 2, Logistic Regression with Resampled Data, based on the comparison between Model 1 and Model 2.This model performs well because it has better accuracy and recall scores.Given its greater recall score, the model is more adept at distinguishing between positive and negative samples.
-
The problem we are attempting to address will determine the performance, which will ultimately affect the outcomes the model produces.
Data for this dataset was generated by edX Boot Camps LLC, and is intended for educational purposes only.