Machine Learning with Low Code
By: Ronny Fahrudin
Tags: Modelling, Machine Learning, Artificial Intelligence, Big Data, Data Science

Introduction

Many people said that building machine learning is so hard and uses complex code. That’s absolutely not true. Actually, we can use a simple code to develop it. But in the real case, the important to build machine learning is knowing the problem and finding the solution. Without knowing the problem, we could not find a solution. Coding is just a bridge to find the solution. So we must bear in our mindset. Therefore, we would have a good sense as a data scientist.

This is good news for us, and we have to say thanks to Mr Moez Ali as the author of PyCaret at Python. We can build machine learning with minimum code and find the best algorithm that matches our dataset to solve the problem. We can build classification, regression, and clustering with PyCaret. But in this section, we are practicing a regression problem to predict house prices in Kaggle. Please download datasets on this to practice.

Here, We only focus on making auto preprocessing and modeling machine learning with Pycaret. We are not yet making exploratory data analysis(EDA). Actually, before modeling, we have to make EDA get some insight and maybe getting new features. But in here, we only build modeling. We suggest following those outlines to better understanding:

Defining Problem Requirement Evaluation Preprocessing with Pycaret Modeling and Evaluation Make Submission

Let’s go…

We start to practice machine learning modeling with low coding step by step base on the outline.

Discussion

1. Defining Problem

We have been Asked a home buyer to describe their dream house, and they probably won’t begin with the height of the basement ceiling or the proximity to an east-west railroad. But this playground competition’s dataset proves that much more influences price negotiations than the number of bedrooms or a white-picket fence.

With 79 explanatory variables describing (almost) every aspect of residential homes in Ames, Iowa, this competition challenges you to predict the final price of each home.

From that problem, we found that objective modeling is to predict the price of each home. So, we use the “SalePrice” variable as a target to predict because the values of that variable are defining the price of each home.

2. Requirement evaluation

a. Matrics evaluation: RMSE

Root-Mean-Squared-Error (RMSE) between the predicted value logarithm and the logarithm of the observed sales price. (Taking logs means that errors in predicting expensive houses and cheap houses will affect the result equally). The best performance is the model with the smallest RMSE score. So we choose the model that produces the smallest RMSE score in this case.

3. Preprocessing with Pycaret

a. Install PyCaret from the notebook

In a notebook, you can install the library of python start with “!”.

!pip install pycaret

b. Load Data

You can download the dataset from this site. After you download that dataset, please load data with the following code:

# import library all we need import os import pandas as pd

from pycaret.regression import * #we import all package with '*' os.chdir('D:/dataset') # we process data from "D:/datasets" train = pd.read_csv('train.csv')

test = pd.read_csv('test.csv') print('shape data train',train.shape)

print('shape data test',test.shape) train.head()

If you run the above code, you can see the result are like that:

Result code load data by author

We have a trainset with 1460 rows and 81 columns. In tests, we have 1459 rows and 80 columns. Do you see NaN values?

Yes, we have missing values here doesn’t explain NaN values. Next, I write the handling of missing values in the data preparation section. We only focus on building a machine learning model.

c. Preprocessing Data

a) Auto preprocessing

Ok. we are finish load the data. We already to make auto preprocessing data. Let’s follow this code:

# our target is SalePrice

sal_clf = setup(train, target='SalePrice')

Result of auto preprocessing by Author

In here, we have NaN values and an automated handle by PyCaret.

4. Modelling and Evaluation

a. Modelling comparison

We can find the best model by making a comparison of all models. Like this:

compare_models()

Result of comparison model by Author

Ok, we found that the best model is Catboost Regressor. Because it has the smallest RMSE score than others. Then we try to predict with catboost.

b. Create and predict with the best model

We make our model with cross-validation. In PyCaret default, cross-validation is 10 fold.

print('result train:') catboost = create_model('catboost', cross_validation = True) print('result predict:')

pred_cb = predict_model(catboost)

Result of creating & predict model

Great! We got the model with a train of RMSE is 27262.18, and the predicted model with the score of RMSE is 23446.68. Tha’s great to make a model because not overfitting. But that is not the best model. And I remember again that you have to do data analysis and data preparation.

5. Make Submission

to submit, you can follow this code:

fcb = finalize_model(catboost) #make model to variables #making

test_predictions = predict_model(fcb, data=test) submission = test_predictions[['Id', 'Label']]

submission.columns = ['Id','SalePrice']

submission.to_csv('submission.csv', index=False)

Result of my submission by Author

That’s my submission score. It has so far from the top leaderboard. It’s obvious because we haven’t done make exploratory data analysis and cleansing data.

Conclusion

In this section, we can make some conclusion that builds a machine learning model with low code is very doable. But, we got the performance model is not better. Because we do not make EDA, preprocessing data, and feature engineering. So, if you want to improve your performance model, please doing those.

I hope my writing to be useful to you.

Thank you, and happy learning!

If you want an Indonesian language version of this post, please go here.

References

[1] Moez Ali, PyCaret Homepage, (2020)

[2] Moez Ali, Regression Module, (2020)