A brief talk about Machine Learning

Diógenes Wallis
CodeX
Published in
8 min readSep 12, 2021
Pepper robot in Tokyo, Japan.

Most people see Machine Learning as robots that will dominate the world, computers winning against people in board games, robot butlers. However, Machine Learning can be things simpler than that and also be used in thousands of different tasks. Personally, my first experience with Machine Learning was in 2019 during my internship at a startup, where I make a system that could automatically count insects using only an RGB image.

I don’t know when was the first time that you have heard about Machine Learning, but probably it didn’t take more than a decade, however, Machine Learning is not a young approach. First of all, Machine Learning is not a magic trick, there is Math behind that, of course, our computer wouldn’t be able to learn if we didn’t set up a well-defined mathematical model.

Machine Learning has a long history, when we look at its timeline we can see that the famous Bayes Theorem dates from 1763. Computers playing backgammon and IBM Deep Blue winning a world chess champion Kasparov date from 1992 and 1997, respectively.

Robot playing chess against a human with a physical board.

Computational power as well data available has increased and a lot of applications were developed, for example, speech recognition, facial recognition, recommendation systems, self-driving cars. Next sections we are going to see the definition of Machine Learning, as well as its types and challenges faced when we are building solutions using Artificial Intelligence.

What is Machine Learning?

You can find a lot of definitions about Machine Learning, but one of them is my favorite:

“A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P if its performance at tasks in T, as measured by P, improves with experience E.”

Tom M. Mitchell

Imagine a robot that executes a task, and you can evaluate its performance. If this robot can achieve better performance as its gain experience, we can say that is Machine Learning. This case could talk about Reinforcement Learning, think the robot is an agent that needs to execute some tasks in a given environment, and each action results in a reward, which we will use to update the agent’s policy so it can receive the greatest reward possible as the time goes.

Reinforcement learning can be used in a lot of applications, including make a computer play a video game, like Super Mario Bros. Sometimes we are better than the machine, but in others cases, we can be surpassed. If you are interested in such a topic I recommend this paper Human-level control through deep reinforcement learning.

Image illustrating Reinforcement Learning process. Source: Free Code Camp.

What if we wish to build a system to detect email spam? If we just decide to create a lot of conditional statements like if and else, maybe we will need hundreds or thousands of simple conditions, probably based on characters/strings from email title or content. Beyond this problem, how could we make updates to our system? Every new spam can result in more conditional statements, so it’s not a good idea, do you agree? Manually updating is pretty boring and as time goes the tendency is to have more and more statements.

One solution would be to use a system where the updates occur automatically, so Machine Learning can be an option! First, we need to labels our emails, so that would cost a lot of time, but it’s necessary because we are going to use supervised learning. After each email has received a classification, we have the data (experience) and we are able to choose a Machine Learning algorithm to solve this problem. This way, if we have new spam, we can add to the data and update our algorithm. Now our emails can be checked for spam automatically.

Machine learning can also be used to help people in understanding data, once the built Machine learning models can show correlations and features that we could not be able to perceive. Every time we need to deal with complex problems where we can have enough amount of data and Machine Learning algorithms can achieve a good performance, we will always choose for Artificial Intelligence solution.

Types of Machine Learning

In this section, we are going to talk about the types of Machine Learning. Depending on the problem we will have a different type of Machine Learning. Here we see supervised, unsupervised, and reinforcement learning.

Unsupervised learning

This kind of learning consists in create clusters in a given dataset. Imagine you have N samples with K features (if we were talking about person structure, these features could be height and weight). Once we have collected the data it is possible to represent each sample by its value features. Imagine we have consumers and each one has a lot of features, like what they buy, how much they pay, how many times they visit the store. Would be interesting if we could find groups of consumers with similar characteristics and try to correspond the new consumers to one of these groups, so we could make a specific approach and make offers more interesting.

Above you can see three clusters where each one must have high homogeneity among the samples inside the clusters and high heterogeneity between any other cluster. Fortunately, each sample has only two features X1 and X2, but if we have more than three features, we could not make a plot illustrating the clusters. K-means is a famous and simple unsupervised learning algorithm. In K-means our clusters are based on prototypes where the sample belongs to the nearest cluster prototype.

Supervised learning

This is the most common type of Machine Learning. My first contact with Machine Learning was using supervised methods. In that case, we need to label each one of our samples. The Machine needs to learn using labeled data and each new input will receive a prediction based on this supervised method. In 2019 and 2020 I worked using this type of Machine Learning. In 2019 I could develop my own insect counting system, where I used image processing techniques to find the insects in the image and extracting features from their contour, I created a table with contour characteristics and the respective labels, in our case: the number of insects. After that, I applied random forest to classify the number of insects. The system was simple enough to run in a Raspberry Pi Zero. Unfortunately, I can’t share images with the contours or the table I created, but you can get some idea from the image below.

Source: “Livestock detection in aerial images using a fully convolutional network”.

In 2020 I start to work with face recognition. My first contact with this problem was in 2019 in my final project from a subject in my university. Here we can find some interesting projects that I made in computer vision. Initially, I used the face_recognition library in python. However, I needed some stronger way to do that in the wild, so I just moved to FaceNet from Google (FaceNet: A Unified Embedding for Face Recognition and Clustering). Basically, we extract 128 features from a face image and classify them, imagine that we have thousands of faces, that is, features vectors, if we wish to recognize you, we just take Euclidean distance to these vectors and classify them as the nearest vector. Usually, we have more than one vector to the same person, so it is a good idea to use KNN and take the most frequent person in these k nearest neighbors.

Image illustrating illumination and pose invariance in the face recognition process developed by Google.

Reinforcement learning

This type of learning is really interesting and different from the others mentioned before. Now you need to have an agent in a given environment where each action is rewarded, so good actions get positive rewards and bad actions penalties or negative rewards. My first contact with Reinforcement learning was in May of this year. I started reading a book called Reinforcement Learning: An Introduction by Sutton and Barto. In this book, we will learn the fundamentals of Reinforcement Learning and the basic techniques. Reinforcement Learning is receiving relevance and each year we have more and more techniques. Some methods like PPO, DDPG, A2C achieve amazing results. One interesting application is to design game levels, I recommend this wonderful paper: PCGRL — Procedural Content Generation via Reinforcement Learning.

The left image is the initial level and the right image shows the level generated by the agent learned using Reinforcement Learning.

Challenges of applied machine learning

When we need to deal with Machine Learning we have two major problems: data problems and algorithm fitting problems. About data problems, we have a low quantity of data, non representative data, bad collected data, outliers, collinearity. If you have bad data you will have a bad Machine Learning model, because “garbage in, garbage out”. So it’s pretty common to spend a lot of time dealing with your data, trying to understand and get value. This process is called exploratory data analysis and maybe this would be the most important part of your pipeline.

About algorithm problems, we have overfitting and underfitting. Te overfitting occurs when your system is pretty good in training data but has a poor capacity for generalization. Reduce model complexity is one way to deal with that, representative data also help a lot. Underfitting is a model that even in training data has a poor performance, increase complexity or choose a more suitable algorithm can solve this problem.

Testing and evaluating

When you are building a Machine Learning model it is important to have 3 datasets: training, validation, and test. Training data is used to fit your model, validation will help to fine-tune where you can use methods like grid-search or random search. Test data is where you check how well your model generalizes to data out of the training dataset. Test data must be used only at the final pipeline, if you use test data to tune hyper-parameters you will face problems like data leakage. I really recommend this book: Machine Learning Yearning. Andrew Ng talks about important topics and this material open my mind to really is training, validation, and testing data. I also would like to say that if you have a small dataset, probably you are going to use cross-validation methods like K-fold. Split data in training and validation is just one way to deal with validation, you can explorer more than that.

Extra section

If you wish to learn more about Machine Learning, I strongly recommend mini-courses from Kaggle. There you will find a lot of materials and you be able to understand important topics faster than you imagine!

--

--

Diógenes Wallis
CodeX
Writer for

I’m a Software Developer with experience in Artificial Intelligence, Data Analysis, and Computer Vision. https://www.linkedin.com/in/diogenes-wallis/