How to Choose the Best Machine Learning Algorithm?

by Carson

Do you want to analyze data or carry out research? If so, machine learning is the perfect tool for you. But there are some things to be aware of when you choose the machine learning algorithm you will use, as this process depends on the purpose and the data in your project. Find out how this works in this article.

Do You Need Machine Learning Algorithms?

Believe it or not, machine learning isn’t always the best way to do every data analysis task. That’s because some simple tasks, like obtaining basic statistical data, don’t need these algorithms at all. Yes, machine learning has the advantage of being flexible and able to learn from whichever dataset you plug it into. But this also comes at a cost, as you’ll need time to write, test, and optimize your model, and also computational resources and time to train them. Therefore, you don’t need to use these models if you’re doing simple tasks, such as extracting information from predictable templates or doing statistics on known datasets. Writing the program yourself will be much faster.

But if you’re doing some complex tasks, like doing predictions or classifications, or analyzing human language, you’ll need machine learning algorithms. The rules behind doing these things are so complex and database-dependent that it takes lots of time to develop and test them each time a new dataset comes along. But instead, machine learning provides a general framework for all of these tasks by letting the computer do the optimizations itself. Therefore, it is an important, if not essential, tool for these kinds of analyses. Let’s look at the type of algorithms and how to choose them in the next section.

Types of Machine Learning Algorithms

Most machine learning tasks use three types of algorithms that have proved themselves versatile across different circumstances.

  1. Supervised learning
  2. Unsupervised learning
  3. Reinforcement learning
Supervised Learning

Supervised learning is a type of machine learning that involves datasets with predefined answers. Essentially, the algorithm looks at the questions and answers to determine the connection between the two. Classification and regression are best done with supervised learning.

For example, if you’re classifying images, you’ll need to provide a dataset that, for each data point, contains an image and the category it should be in. As the model tries to understand the rationale behind the dataset and tries to recreate it, it occasionally makes some mistakes or uncertain decisions. In this case, the model adjusts itself to make a better fit to answer more “questions” correctly.

Note that an excessively good fit is also a problem, as overfitting often happens in this case. Therefore, it’s necessary to split the data into the “train” and “test” groups. Only the training group will be sent to the model for training, while the testing group will be used for validation to monitor whether the model responds well to real-world data.

Unsupervised Learning

Unsupervised learning is a type of machine learning, where the data doesn’t come with the answers. Instead, the model has to discover the patterns behind the dataset by itself, and classify it into different categories. This is especially helpful when dealing with multidimensional data, where it can be really painful to create and optimize supervised learning datasets. Example use cases involve clustering and association.

For example, you have a dataset that records the personality traits of different people, and you want to split them into categories to see which personality type is more common. In this case, a few data points about different behaviors are collected for every person in the study. You’ll then plug it into a clustering algorithm that tries to deduce the differences between each data point so that it can pick out groups with similar qualities.

Reinforcement Learning

Reinforcement learning is a type of machine learning where a model, known as the agent, finds the best way to behave by interacting with the environment. It performs some actions, absorbs some feedback, and then improves the next time they complete the action again. The feedback is often abstract in the real world, but in these tasks, it tends to be a number that measures how well the model performed. Essentially, it is learning through trial and error.

For instance, if you would like to teach a model to play a game, you would need reinforcement learning. The actions are so complex, dynamic, and sometimes chaotic, that they can’t be easily expressed as inputs for supervised or even unsupervised learning. Therefore, the best way to do it is to let the model play the game many times and learn the tactics by itself. At first, the model will perform poorly and lose games quickly as it just randomly guesses actions. But as it learns from the feedback, its performance improves so that it gains more success playing the game.

Common Algorithms

Most machine learning models only use a few algorithms as they are so versatile. Here are some well-known algorithms that we use for most tasks:

  1. Linear regression
  2. Logistic regression
  3. Decision tree
  4. Support vector machine (SVM)
  5. K-means clustering
  6. K-nearest neighbors (kNN)
  7. Neural networks

1. Linear Regression

In a linear regression task, the model explores the relationship between the input variable (x) and the output variable (y). Basically, this simple method models the relationship as ax + b = y, where a and b are the coefficients. Then, as it fits toward the data, it optimizes the value of a and b so that it’s as close to the actual values of y as possible.

This is very helpful for datasets that exhibit a linear nature, as it can obtain the average values of the output value in terms of the input value. It is also helpful in detecting correlations. However, this doesn’t work well in nonlinear datasets, as the degree of the prediction only goes up to 1.

Blue: a set of 100 random data points
Red: the best-fit linear function for the data
Note that it doesn’t produce a good fit, because the data is highly nonlinear (it is actually random!)

2. Logistic Regression

Despite the word “regression” in its name, logistic regression is actually used for classification. Therefore, the data in this model comprises answers to binary questions, whether it falls into a category or doesn’t. The exact function in this algorithm differs according to the actual model, but the output value is always between 0 and 1. Again, the parameters in this function are tuned so that the output fits as close to the actual data as possible.

Blue: graph of the sigmoid function, which is a logistic function
Red: graph of 0.2x + 0.1, a linear function

3. Decision Tree

A decision tree is a model that makes decisions based on certain parameters or properties. Basically, it works based on a series of decisions — if the input value is greater than some value, for example, it jumps to the next branch. Then, the model faces more things to check, like whether the value is prime. All the possibilities, mapped on a graph, look like a tree. Thus, this is called a decision tree. Please refer to the image below if you need help understanding what I am talking about.

An example of a typical decision tree

Decisions are usually discrete, so you might expect it to be used in classification tasks. This is indeed the case, but it can also be used in regression. When certain conditions hold, you can adjust the output value with a certain function based on the input value and all the decisions the model has made. Essentially, this looks like a piecewise function.

4. Support Vector Machine

In a support vector machine, we use vectors of many numbers to describe the attributes of a data point. This maps it to a high-dimensional plane. After that, we draw a line on the hyperplane to split the data into multiple categories. The function of that line is the kernel function, and its location must be optimized through machine learning. This is especially useful in classification algorithms.

5. K-means Clustering

K-means clustering is one of the most popular methods for unsupervised clustering tasks, as it allows the user to specify how many clusters the data needs to be classified to. For example, if k is 5, the algorithm will group the data into 5 clusters. How does it work? First, it initializes some categories by choosing some points, known as cluster centroids. Then, it uses the Euclidean distance method to locate the closest neighbors to the centroids. Finally, the process repeats until the whole dataset is classified into k clusters.

A random dataset, clustered using the k-means algorithm with k=4

This algorithm is suitable for any clustering task, like the example I mentioned in the “unsupervised learning” section. But I’ll give you another example here. Suppose that you would like to group your customers. There are many data points to consider, like their interests, geographic location, or purchasing history. In this case, an unsupervised clustering algorithm becomes the best choice, and k-means clustering is excellent for this purpose. By segmenting these customers into different categories, your company would have a better idea of what they will purchase, and thus provide targeted marketing tactics.

6. K-nearest Neighbors

Unlike k-means clustering, which has a similar name, the k-nearest neighbors method isn’t actually used for clustering. Instead, it is a supervised algorithm for classification and regression tasks. Nevertheless, it’s still good at processing multidimensional data; specifically, it uses the Euclidean distance method, which is the same algorithm as the k-means method. But instead of a dataset and the number of categories, this algorithm feeds on a trained model that classifies the data into specific categories based on their landmark features.

7. Neural Networks

Lastly, and the most importantly, we have the most versatile and powerful type of machine learning — deep neural networks. Basically, it sets up a network of neurons that each accept inputs, process them, and return outputs. just like a computer. One layer of neurons then pipes the output into the next one for further processing. And by training the neural network, the individual parameters in the neurons are adjusted so that they return accurate predictions. That’s also why they are mainly used for supervised and reinforcement learning tasks — because there must be frames of reference in the fine-tuning process.

An illustration of the architecture of a neural network

Therefore, they are suitable for regression and classification tasks and tasks involving interacting with outside agents, such as playing games. For example, if you want to classify a group of images into two categories, a deep neural network will probably yield the best results. First, you would collect many photos and classify them manually into these categories. Note that you must split the dataset into two categories (training and testing). Then, you set the neural network parameters, determining how deep the network goes and how many output values there are (in this case, 2). Finally, you train the model with the training data and evaluate it with the test data.

However, note that you have many things to consider when crafting your deep learning model. Setting the model parameters wrong can easily result in underfitting or overfitting, especially when the parameters are so flexible. Therefore, looking through the list of adjustable parameters is crucial to ensure you optimize its performance. For instance, you’re underfitting if you perform badly with the training and testing. Increase model complexity (such as adding more layers) in this case. If you do well in the training but poorly in the testing, you’re overfitting. Decrease model complexity or add dropout layers if this happens.


In this article, we’ve introduced different machine learning models and architectures so that you can choose the best one to implement. If you are really going for accuracy, neural networks are recommended. But if you prefer simplicity or cost-effectiveness, other options can also appeal. But if your task is really simple, you don’t need to use machine learning at all. Remember to choose the right way of doing things to get the best model out of less training time! If you would like us to include more content, please leave your recommendations in the comment section below.

Related Posts

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.