Predicting Loan Default using Machine Learning with MindsDB

Eliel Godsent
4 min readJul 12, 2022

--

MindsDB

Introduction

A loan is money borrowed to someone (the debtor) with the intent to pay back at an agreed date. Ideally, things should go as planned but when the debtor fails to pay the person they borrowed the loan from (the creditor), the debtor is said to have defaulted on the loan. This is what loan default is

It is the event of a debtor not paying their loan…

It is then important for creditors/loan companies to know/predict if a certain debtor will default or not. This is a problem that machine learning solves, this is a classification machine learning problem.

As with every machine learning problem, data is the major ingredient in solving it. The dataset for this problem is from the Zindi Loan Default Prediction Challenge for DSN

This tutorial is to showcase how MindsDB performs in solving this problem. We will be exploring how we can use a machine learning model to classify negative and positive cases for predicting loan default. MindsDB allows you to train your model from a CSV format directly, and you will:

  • Load your dataset
  • Create a predictor, and,
  • Make predictions

Load your dataset

Data wrangling

If you go through the dataset, you will find that it is split into three different files, you will first wrangle the data to suit your requirements,

Here, I use python to wrangle the data, you can however use your desired tool (excel perhaps…) or copy my snippet below…

Now that the dataset has been cleaned and stored into a .csv file, you can upload it to the MindsDB cloud…

Using the MindsDB GUI

To use the MindsDB GUI, you will need to access the MindsDB Cloud Tool and sign up for an account if you haven’t yet, then, you will be automatically directed to the editor.

While on the editor, you can add your data via several means, but as earlier mentioned, you will upload your dataset as a .csv…

On the “Select your data source” screen, click on “Files” next to “Databases” and you should see the screen below:

Click on the “Import File” icon and select your .csv file.

Give your table a name and hit the “Save and Continue” button.

NOTE: Use snake or camel casing when uploading files

If you do all things well, you should see a result like this:

Now that you have loaded your dataset, you are now to…

Create a Predictor

Creating a predictor in MindsDB is as easy as four lines of code. Copy and paste the code below into your SQL editor to make a predictor

If all is successful, you should see this screen below:

To confirm this and view details of your model like the accuracy, use the following code:

and you can see details of your model…

PS: You can see the accuracy is low, this is probably due to low data…

Now that you have created your predictor model, now is time to…

Make a prediction

You can use the following query to make a prediction… pay attention to using new/unseen/untrained data…

PS: Pay attention to highlight your prediction query and run it

and viola! you just made a prediction!

Conclusion

And that’s it you shining rockstar! you are now an ML Wizard making predictions straight from the data! This is a taste of the awesome power of MindsDB.

Some important things to note:

  • More data improves the accuracy of the model
  • Your table names should not contain spaces but rather be in snake or camel casing
  • Highlight your prediction query and run it to see the result
  • MindsDB is fast and very helpful

Want to try MindsDB out for yourself?

Sign up for a free MindsDB account and join our community!

Engage with the MindsDB community on Slack or Github to ask questions, share and express ideas and thoughts!

For more, check out other tutorials and MindsDB documentation.

--

--

Responses (2)