In this guide, we’ll take a practical, concise tour through modern machine learning algorithms. While other such lists exist, they don’t really explain the practical tradeoffs of each algorithm, which we hope to do here. We’ll discuss the advantages and disadvantages of each algorithm based on our experience.

Categorizing machine learning algorithms is tricky, and there are several reasonable approaches; they can be grouped into generative/discriminative, parametric/non-parametric, supervised/unsupervised, and so on.

For example, Scikit-Learn’s documentation page groups algorithms by their **learning mechanism****. **This produces categories such as:

- Generalized linear models
- Support vector machines
- Nearest neighbors
- Decision trees
- Neural networks
- And so on…

However, from our experience, this isn’t always the most practical way to group algorithms. That’s because for applied machine learning, you’re usually not thinking, *“boy do I want to train a support vector machine today!”*

Instead, you usually have an end goal in mind, such as predicting an outcome or classifying your observations.

Therefore, we want to introduce another approach to categorizing algorithms, which is by** machine learning task.**

**No Free Lunch**

In machine learning, there’s something called the “No Free Lunch” theorem. In a nutshell, it states that no one algorithm works best for every problem, and it’s especially relevant for supervised learning (i.e. predictive modeling).

For example, you can’t say that neural networks are always better than decision trees or vice-versa. There are many factors at play, such as the size and structure of your dataset.

As a result, you should **try many different algorithms for your problem**, while using a hold-out “test set” of data to evaluate performance and select the winner.

Of course, the algorithms you try must be appropriate for your problem, which is where picking the right machine learning task comes in. As an analogy, if you need to clean your house, you might use a vacuum, a broom, or a mop, but you wouldn't bust out a shovel and start digging.

**Machine Learning Tasks**

This is Part 1 of this series. In this part, we will cover the "Big 3" machine learning tasks, which are by far the most common ones. They are:

In Part 2, we will cover dimensionality reduction, including:

- Feature Selection
- Feature Extraction

Two notes before continuing:

- We will not cover domain-specific adaptations, such as natural language processing.
- We will not cover every algorithm. There are too many to list, and new ones pop up all the time. However, this list
*will*give you a representative overview of successful contemporary algorithms for each task.

## 1. Regression

Regression is the supervised learning task for modeling and predicting **continuous, numeric** variables. Examples include predicting real-estate prices, stock price movements, or student test scores.

Regression tasks are characterized by *labeled datasets that have a numeric target variable*. In other words, you have some "ground truth" value for each observation that you can use to *supervise* your algorithm.

#### 1.1. (Regularized) Linear Regression

Linear regression is one of the most common algorithms for the regression task. In its simplest form, it attempts to fit a straight hyperplane to your dataset (i.e. a straight line when you only have 2 variables). As you might guess, it works well when there are linear relationships between the variables in your dataset.

In practice, simple linear regression is often outclassed by its regularized counterparts (LASSO, Ridge, and Elastic-Net). Regularization is a technique for penalizing large coefficients in order to avoid overfitting, and the strength of the penalty should be tuned.

**Strengths:**Linear regression is straightforward to understand and explain, and can be regularized to avoid overfitting. In addition, linear models can be updated easily with new data using stochastic gradient descent.**Weaknesses:****Implementations:**Python / R

#### 1.2. Regression Tree (Ensembles)

Regression trees (a.k.a. decision trees) learn in a hierarchical fashion by repeatedly splitting your dataset into separate branches that maximize the information gain of each split. This branching structure allows regression trees to naturally learn non-linear relationships.

Ensemble methods, such as Random Forests (RF) and Gradient Boosted Trees (GBM), combine predictions from many individual trees. We won't go into their underlying mechanics here, but in practice, RF's often perform very well out-of-the-box while GBM's are harder to tune but tend to have higher performance ceilings.

**Strengths:**Decision trees can learn non-linear relationships, and are fairly robust to outliers. Ensembles perform very well in practice, winning many classical (i.e. non-deep-learning) machine learning competitions.**Weaknesses:**Unconstrained, individual trees are prone to overfitting because they can keep branching until they memorize the training data. However, this can be alleviated by using ensembles.**Implementations:**Random Forest - Python / R, Gradient Boosted Tree - Python / R

#### 1.3. Deep Learning

Deep learning refers to multi-layer neural networks that can learn extremely complex patterns. They use "hidden layers" between inputs and outputs in order to model *intermediary representations* of the data that other algorithms cannot easily learn.

They have several important mechanisms, such as convolutions and drop-out, that allows them to efficiently learn from high-dimensional data. However, deep learning still requires much more data to train compared to other algorithms because the models have orders of magnitudes more parameters to estimate.

**Strengths:**Deep learning is the current state-of-the-art for certain domains, such as computer vision and speech recognition. Deep neural networks perform very well on image, audio, and text data, and they can be easily updated with new data using batch propagation. Their architectures (i.e. number and structure of layers) can be adapted to many types of problems, and their hidden layers reduce the need for feature engineering.**Weaknesses:**Deep learning algorithms are usually not suitable as general-purpose algorithms because they require a very large amount of data. In fact, they are usually outperformed by tree ensembles for classical machine learning problems. In addition, they are computationally intensive to train, and they require much more expertise to tune (i.e. set the architecture and hyperparameters).**Implementations:**Python / R

#### 1.4. Honorable Mention: Nearest Neighbors

Nearest neighbors algorithms are "instance-based," which means that that save each training observation. They then make predictions for new observations by searching for the most similar training observations and pooling their values.

These algorithms are memory-intensive, perform poorly for high-dimensional data, and require a meaningful distance function to calculate similarity. In practice, training regularized regression or tree ensembles are almost always better uses of your time.

## 2. Classification

Classification is the supervised learning task for modeling and predicting **categorical** variables. Examples include predicting employee churn, email spam, financial fraud, or student letter grades.

As you'll see, many regression algorithms have classification counterparts. The algorithms are adapted to predict a class (or class probabilities) instead of real numbers.

#### 2.1. (Regularized) Logistic Regression

Logistic regression is the classification counterpart to linear regression. Predictions are mapped to be between 0 and 1 through the logistic function, which means that predictions can be interpreted as class probabilities.

The models themselves are still "linear," so they work well when your classes are linearly separable (i.e. they can be separated by a single decision surface). Logistic regression can also be regularized by penalizing coefficients with a tunable penalty strength.

**Strengths:**Outputs have a nice probabilistic interpretation, and the algorithm can be regularized to avoid overfitting. Logistic models can be updated easily with new data using stochastic gradient descent.**Weaknesses:**Logistic regression tends to underperform when there are multiple or non-linear decision boundaries. They are not flexible enough to naturally capture more complex relationships.**Implementations:**Python / R

#### 2.2. Classification Tree (Ensembles)

Classification trees are the classification counterparts to regression trees. They are both commonly referred to as "decision trees" or by the umbrella term "classification and regression trees (CART)."

**Strengths:**As with regression, classification tree ensembles also perform very well in practice. They are robust to outliers, scalable, and able to naturally model non-linear decision boundaries thanks to their hierarchical structure.**Weaknesses:**Unconstrained, individual trees are prone to overfitting, but this can be alleviated by ensemble methods.**Implementations:**Random Forest - Python / R, Gradient Boosted Tree - Python / R

#### 2.3. Deep Learning

To continue the trend, deep learning is also easily adapted to classification problems. In fact, classification is often the more common use of deep learning, such as in image classification.

**Strengths:**Deep learning performs very well when classifying for audio, text, and image data.**Weaknesses:**As with regression, deep neural networks require very large amounts of data to train, so it's not treated as a general-purpose algorithm.**Implementations:**Python / R

#### 2.4. Support Vector Machines

Support vector machines (SVM) use a mechanism called kernels, which essentially calculate distance between two observations. The SVM algorithm then finds a decision boundary that maximizes the distance between the closest members of separate classes.

For example, an SVM with a linear kernel is similar to logistic regression. Therefore, in practice, the benefit of SVM's typically comes from using non-linear kernels to model non-linear decision boundaries.

**Strengths:**SVM's can model non-linear decision boundaries, and there are many kernels to choose from. They are also fairly robust against overfitting, especially in high-dimensional space.**Weaknesses:**However, SVM's are memory intensive, trickier to tune due to the importance of picking the right kernel, and don't scale well to larger datasets. Currently in the industry, random forests are usually preferred over SVM's.**Implementations:**Python / R

#### 2.5. Naive Bayes

Naive Bayes (NB) is a very simple algorithm based around conditional probability and counting. Essentially, your model is actually a probability table that gets updated through your training data. To predict a new observation, you'd simply "look up" the class probabilities in your "probability table" based on its feature values.

It's called "naive" because its core assumption of conditional independence (i.e. all input features are independent from one another) rarely holds true in the real world.

**Strengths:**Even though the conditional independence assumption rarely holds true, NB models actually perform surprisingly well in practice, especially for how simple they are. They are easy to implement and can scale with your dataset.**Weaknesses:**Due to their sheer simplicity, NB models are often beaten by models properly trained and tuned using the previous algorithms listed.**Implementations:**Python / R

## 3. Clustering

Clustering is an unsupervised learning** **task for finding natural groupings of observations (i.e. clusters) based on the inherent structure within your dataset. Examples include customer segmentation, grouping similar items in e-commerce, and social network analysis.

Because clustering is unsupervised (i.e. there's no "right answer"), data visualization is usually used to evaluate results. If there is a "right answer" (i.e. you have pre-labeled clusters in your training set), then classification algorithms are typically more appropriate.

#### 3.1. K-Means

K-Means is a general purpose algorithm that makes clusters based on *geometric distances* (i.e. distance on a coordinate plane) between points. The clusters are grouped around centroids, causing them to be globular and have similar sizes.

This is our recommended algorithm for beginners because it's simple, yet flexible enough to get reasonable results for most problems.

**Strengths:**K-Means is hands-down the most popular clustering algorithm because it's fast, simple, and surprisingly flexible if you pre-process your data and engineer useful features.**Weaknesses:**The user must specify the number of clusters, which won't always be easy to do. In addition, if the true underlying clusters in your data are not globular, then K-Means will produce poor clusters.**Implementations:**Python / R

#### 3.2. Affinity Propagation

Affinity Propagation is a relatively new clustering technique that makes clusters based on *graph distances* between points. The clusters tend to be smaller and have uneven sizes.

**Strengths:**The user doesn't need to specify the number of clusters (but does need to specify 'sample preference' and 'damping' hyperparameters).**Weaknesses:**The main disadvantage of Affinity Propagation is that it's quite slow and memory-heavy, making it difficult to scale to larger datasets. In addition, it also assumes the true underlying clusters are globular.**Implementations:**Python / R

#### 3.3. Hierarchical / Agglomerative

Hierarchical clustering, a.k.a. agglomerative clustering, is a suite of algorithms based on the same idea: (1) Start with each point in its own cluster. (2) For each cluster, merge it with another based on some criterion. (3) Repeat until only one cluster remains and you are left with a *hierarchy* of clusters.

**Strengths:**The main advantage of hierarchical clustering is that the clusters are not assumed to be globular. In addition, it scales well to larger datasets.**Weaknesses:**Much like K-Means, the user must choose the number of clusters (i.e. the level of the hierarchy to "keep" after the algorithm completes).**Implementations:**Python / R

#### 3.4. DBSCAN

DBSCAN is a density based algorithm that makes clusters for *dense regions* of points. There's also a recent new development called HDBSCAN that allows varying density clusters.

**Strengths:**DBSCAN does not assume globular clusters, and its performance is scalable. In addition, it doesn't require every point to be assigned to a cluster, reducing the noise of the clusters (this may be a weakness, depending on your use case).**Weaknesses:**The user must tune the hyperparameters 'epsilon' and 'min_samples,' which define the density of clusters. DBSCAN is quite sensitive to these hyperparameters.**Implementations:**Python / R

## Parting Words

We've just taken a whirlwind tour through modern algorithms for the "Big 3" machine learning tasks: Regression, Classification, and Clustering.

In Part 2, we will look at algorithms for Dimensionality Reduction, including Feature Selection and Feature Extraction.

However, we want to leave you with a few words of advice based on our experience:

**First... practice, practice, practice.**Reading about algorithms can help you find your footing at the start, but true mastery comes with practice. As you work through projects and/or competitions, you'll develop practical intuition, which unlocks the ability to pick up almost any algorithm and apply it effectively.**Second... master the fundamentals.**There are dozens of algorithms we couldn't list here, and some of them can be quite effective in specific situations. However, almost all of them are some adaptation of the algorithms on this list, which will provide you a strong foundation for applied machine learning.**Finally, remember that better data beats fancier algorithms.**In applied machine learning, algorithms are commodities because you can easily switch them in and out depending on the problem. However, effective exploratory analysis, data cleaning, and feature engineering can significantly boost your results.

If you'd like to learn more about the applied machine learning workflow and how to efficiently train professional-grade models, we invite you to sign up for our free 7-day email crash course.

For more over-the-shoulder guidance, we also offer a comprehensive masterclass that further explains the intuition behind many of these algorithms and teaches you how to apply them to real-world problems.

## Leave A Response