Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: [email protected]
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-François Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Take our 85+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

Publication

Applying Classification Algorithms to Past Loan Data
Latest

Applying Classification Algorithms to Past Loan Data

Last Updated on July 5, 2022 by Editorial Team

Author(s): Gencay I.

Originally published on Towards AI the World’s Leading AI and Technology News and Media Company. If you are building an AI-related product or service, we invite you to consider becoming an AI sponsor. At Towards AI, we help scale AI and technology startups. Let us help you unleash your technology to the masses.

KNN, Decision Tree, Support Vector Machine, Logistic Regression

Photo by Scott Graham onΒ Unsplash

In this data set, I am going to conduct classification machine learning analysis on past loan data whichΒ are;

Content Table
Β· Data Visualization
Β· One hot encoding
Β· Feature Selection
Β· Normalize Data
Β· Classification
∘ K Nearest Neighbor
∘ Evaluation Metrics of KNN
∘ Decision Tree
∘ Evaluation Metrics of Decision Tree
∘ Support Vector Machine
∘ Evaluation Metrics of SVM
∘ Logistic Regression
∘ Evaluation Metrics of Logistic Regression
∘ Model Evaluation using a Test set
∘ Jaccard Scores
∘ F1 Scores
∘ Final Evaluation

Let's load the necessary libraries;

Image byΒ Author

The Loan_train.csv data set includes details of 346 customers whose loans are already paid off or defaulted.

Image byΒ Author

Lets loadΒ data;

Image byΒ Author

It is always efficient to look shape of data, to see the bigΒ picture.

Image byΒ Author

Now let's fix the data frames columnΒ type.

Image byΒ Author

Data Visualization

Let's see how many of each class is in our dataΒ set

Image byΒ Author

Let's plot some columns to understand better

Image byΒ Author
Image byΒ Author

Let's look at the day of week people get theΒ loan

Image byΒ Author

We see that people who get the loan at the end of the week don't pay it off, so let's use Feature binarization to set threshold values less than dayΒ 4

Image byΒ Author

Now it is time to change categorical features to numerical because we will use machine learning algorithms.

Image byΒ Author

86 % of females pay their loans while only 73 % of males pay theirΒ loan

Let's convert male to 0 and female toΒ 1:

Image byΒ Author

One hotΒ encoding

Now let’s look education column.

Image byΒ Author
Image by Author- These are the features that we’re gonna use in our prediction.

We use dummies to transform education from categorical to numerical.

Image byΒ Author

Feature Selection

Let’s define features;

Image byΒ Author

Now it is time to define ourΒ label;

Image byΒ Author

Normalize Data

Image byΒ Author

Classification

These are the classification techniques that I will use in thisΒ Dataset.

  • K Nearest Neighbor(KNN)
  • Decision Tree
  • Support VectorΒ Machine
  • Logistic Regression

K NearestΒ Neighbor

Now it is time to split train and test data, as usual, 0.2–0.8Β portion.

Image byΒ Author
Image byΒ Author
Image byΒ Author

Now it is time to look into the accuracy of test and trainΒ data.

Image byΒ Author

To define bestΒ K;

Image byΒ Author

As we can see result 7 is the best K for ourΒ data.

Image byΒ Author
Image byΒ Author
Image by Author- Fit theΒ Model

Evaluation Metrics ofΒ KNN

Image byΒ Author

Decision Tree

Now let's try using Decision Tree algorithms.

Image byΒ Author
Image byΒ Author

To define the best of theΒ depth;

Image byΒ Author

5 is the best depth score according to accuracyΒ scores.

Image byΒ Author

Let’s conduct our algorithm then and evaluate;

Evaluation Metrics of DecisionΒ Tree

Image byΒ Author

Support VectorΒ Machine

Now let’s useΒ SVM.

Image byΒ Author

To find out the best model inΒ SVM;

Image byΒ Author
Image byΒ Author
Image byΒ Author

Evaluation Metrics ofΒ SVM

Image byΒ Author

Logistic Regression

Now it is time to use Logistic Regression.

Lets lock andΒ load;

Image byΒ Author

Train-test split;

Image byΒ Author

Find the bestΒ solver;

Image byΒ Author
Image byΒ Author

Evaluation Metrics of Logistic Regression

Image byΒ Author

Model Evaluation using a TestΒ set

Image byΒ Author
Image byΒ Author

Data processing;

Image byΒ Author

Jaccard Scores

Image byΒ Author
Image byΒ Author
Image byΒ Author
Image byΒ Author

F1 Scores

Image byΒ Author
Image byΒ Author
Image byΒ Author
Image byΒ Author

Final Evaluation

Image byΒ Author

Thanks, IBM for Machine Learning Tutorial which gets meΒ there.


Applying Classification Algorithms to Past Loan Data was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.

Join thousands of data leaders on the AI newsletter. It’s free, we don’t spam, and we never share your email address. Keep up to date with the latest work in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming aΒ sponsor.

Published via Towards AI

Feedback ↓