Supervised Learning

Supervised learning is a type of machine learning technique that uses labeled data for training models to make predictions. In supervised learning, a model learns to perform a classification or regression task using a known set of input data and responses.

How Supervised Learning Works

Supervised learning is the most common type of machine learning. It uses a known data set (called the training data set) to train an algorithm with a known set of input data (called features) and known responses. The training data set includes labeled input data that pairs with desired outputs or response values. From this data set, the supervised learning algorithm seeks to create a model by discovering relationships between the features and output data, and then makes predictions of the response values for a new data set.

Supervised learning can be used in several engineering and scientific fields for developing models that solve real-world problems. For example, consider clinicians having data on previous patients, including age, weight, height, and blood pressure. They know whether the previous patients had heart attacks and want to predict whether a new patient is at risk for a heart attack. This can be done by using supervised learning to model the existing data.

A simplified workflow of supervised learning, showing data and labels as inputs in the training phase and new data with a predicted response in the inference phase.

The training and inference phases in supervised learning.

A typical supervised learning workflow involves steps such as data preparation, algorithm selection, model training, and model evaluation. Because supervised learning relies on labeled data to train models, it is crucial that the training data is realistic. For example, if the model is going to be used in a noisy environment, then the training data must also contain realistic levels of noise. Validation is another important step in supervised learning, to ensure that the model generalizes well to unseen data and to prevent overfitting.

Improving Supervised Learning Model

Improving a supervised learning model—that is, increasing its accuracy and predictive power—often involves feature engineering and hyperparameter tuning. Feature engineering is the process of turning raw data into features to be used as inputs of a machine learning model. Hyperparameter tuning involves identifying the set of parameters that provides the best model.

Workflow diagram for improving a supervised learning model. After feature selection and transformation, the model is trained and tuned iteratively.

Applying feature engineering and hyperparameter tuning to improve the performance of a supervised learning model.

Feature engineering involves steps such as feature selection and feature transformation. In feature selection, you identify the most relevant features, or variables, that provide the best predictive power in modeling your data. During feature transformation, existing features are turned into new features using principal component analysis, nonnegative matrix factorization, factor analysis, and other techniques.

In hyperparameter tuning, you try to find the best settings for the parameters that control the learning process, such as learning rate, batch size, and number of epochs.

Supervised Learning vs. Unsupervised Learning

Supervised and unsupervised learning are both types of machine learning.

Supervised learning techniques include classification and regression, and unsupervised learning techniques include clustering.

Two types of machine learning: supervised and unsupervised learning.

The main difference between supervised and unsupervised learning is that supervised learning requires labeled training data to train a machine learning model. In contrast, unsupervised learning makes use of unlabeled data to uncover hidden relationships in the data without human intervention. Supervised learning results can be more accurate than unsupervised learning results due to the presence of labeled data. However, acquiring labeled data often requires human effort and can be time-consuming, expensive, and impractical in certain cases.

Prior to applying supervised learning, unsupervised learning is sometimes used to discover patterns in the input data and identify features for supervised learning. In addition to identifying features, the correct category or response needs to be identified for all observations in the training set. Semi-supervised learning, also a machine learning technique, lets you train models with less labeled data and thus reduce the labeling effort.

Types of Supervised Learning

The main types of machine learning models created by supervised learning algorithms are classification and regression models. For each type of task, classification or regression, different algorithms can be used for modeling your data.

Supervised learning algorithms used for classification models include naïve Bayes, nearest neighbor, and discriminant analysis. Algorithms for regression models include linear regression, generalized linear models, and Gaussian process. Support vector machines, decision trees, ensemble methods and neural networks are used for both classification and regression.

Types of supervised learning algorithms.

Supervised Learning for Classification

In supervised learning, classification refers to separating the data into specific classes or categories. The goal is to assign a class (or label) from a finite set of classes to an observation. That is, the responses of a classification model are categorical variables.

Typical applications include medical imaging, speech recognition, and credit scoring. Examples include determining whether an email is genuine or spam or whether equipment parts are defective or good.

Popular Supervised Learning Models for Classification Tasks
Logistic regression fits a model that can predict the probability of a binary response belonging to one class or the other. Discriminant analysis classifies data by finding linear combinations of features by assuming that different classes generate data based on Gaussian distributions. k-nearest neighbor (kNN) categorizes objects based on the classes of their nearest neighbors in the data set. kNN predictions assume that objects near each other are similar. Naive Bayes classifiers assume that the presence of a feature in a class is independent of other features. It classifies new data based on the highest probability of it belonging to a particular class.
Scatter plot with straight line separating data points into two classes.
Curved line separating data points into two classes.
Illustration of data points at different distances from their nearest neighbor.
        
Illustration of data grouped into concentric classes.

Supervised Learning for Regression

You can use regression techniques in supervised learning to understand the relationship between response and input variables. They are useful for data sets with a range of values or when the response is a real number, like temperature or time until equipment failure. That is, regression models predict continuous responses. Typical applications include electricity load forecasting, predicting the remaining cycle life of batteries, algorithmic trading, disease incidence, forecasting stock prices, and acoustic signal processing.

Popular Supervised Learning Algorithms for Regression Tasks
Linear regression is a statistical modeling technique used to describe a continuous response variable as a linear function of one or more predictor variables. Because linear regression models are simple to interpret and easy to train, they are often the first model to be fitted to a new data set. Nonlinear regression is a statistical modeling technique that helps describe nonlinear relationships in experimental data. Nonlinear regression models are generally assumed to be parametric, where the model is described as a nonlinear equation. A special class of nonlinear models, generalized linear models use linear methods. Their approach involves fitting a linear combination of the inputs to a nonlinear function (the link function) of the outputs.
Scatter plot with linear trendline.
Scatter plot with nonlinear trendline.
     
Curved line fit to data points.

Supervised Learning for Classification or Regression

Several supervised learning algorithms can be used for both classification and regression tasks.

Popular Supervised Learning Algorithms for Both Classification and Regression Tasks
Decision trees let you predict responses to data by following the decisions in the tree from the root (beginning) down to a leaf node. A tree consists of branching conditions where the value of a predictor is compared with a trained weight. The branch number and weight values are determined during training. Support vector machines (SVMs) classify data by finding the hyperplane that best separates all data points of one class from those of the other class. For SVM regression, instead of finding a hyperplane that separates data, algorithms find a model that deviates from the measured data by a value no greater than a small amount, with parameter values that are as small as possible (to minimize sensitivity to error). Neural networks are adaptive systems that learn by using interconnected nodes or neurons in a layered structure that resembles a human brain. A neural network can learn from data, so it can be trained to recognize patterns, classify data, and forecast future events. A neural network’s behavior is defined by the way its individual elements are connected and by the strength, or weights, of those connections. These weights are automatically adjusted during training.
Diagram of decision tree with one root at the top, splitting into several layers of branches.
Illustration with straight line separating data points into two classes.
Model showing three layers of several interconnected nodes.

Deep learning, a specialized form of machine learning, leverages deep neural networks to handle more complex tasks and larger data sets. Popular deep learning algorithms such as convolutional neural networks (CNNs), recurrent neural networks (RNNs), and long short-term memory (LSTM) networks are typically supervised.

Choosing the Right Supervised Learning Algorithm

When you are choosing a supervised learning algorithm for your data, you must consider the trade-offs between different algorithms, such as their computational and memory requirements, predictive accuracy, and interpretability. This process might involve trial and error and can be made easier by applying automated machine learning (AutoML).

Graph showing supervised learning algorithms plotted with interpretability on the x-axis versus their predictive power on the y-axis.

The trade-off between predictive power and interpretability for several supervised learning algorithms.

Why Supervised Learning Is Important

Supervised learning is a major area of machine learning and artificial intelligence. Engineers and scientists are using supervised learning to build AI models to solve real-world problems. For instance, in virtual sensor modeling, AI models that are used for developing these sensors are trained with supervised learning algorithms. Some of the application areas for supervised learning are:

  • Bioinformatics and medical devices: Supervised learning techniques are widely used in healthcare for medical imaging, tumor detection, and drug discovery. Supervised learning can also be used for signal-based tasks such as classifying ECG data to distinguish between arrhythmia, congestive heart failure, and normal sinus rhythm.
  • Energy production: By using supervised learning for regression, engineers can predict energy prices, forecast electricity load, and create models for various renewable energy applications.
  • Industrial automation: Supervised learning can be used to develop predictive models for anomaly detection, fault detection, and diagnosis.
  • Quantitative finance and risk assessment: Supervised learning algorithms are used for credit scoring, algorithmic trading, stock price prediction, and bond classification.

Real-World Supervised Learning Example

Battery state of charge (SOC) is the level of charge of an electric battery relative to its capacity measured as a percentage. SOC must be accurately estimated in many applications, such as in electric vehicles. Lithium-ion SOC estimation using a physics-based modeling approach is very complex due to varying operating conditions and significant device variability even with batteries from the same manufacturer.

Using supervised learning to create a predictive model for SOC estimation is a data-driven approach that can help address these challenges. The model can predict the state of charge of a vehicle’s lithium-ion battery from time series data that represents various battery measurements, such as voltage, current, and temperature, and derived features, such as average voltage and current. Learn more about this example.

Five line charts showing true and predicted SOC using supervised learning; the first shows the training data, and the other four show test data plotted at different temperatures.

True vs. predicted SOC using a Gaussian process regression model in Statistics and Machine Learning Toolbox. (See code.)

Supervised Learning with MATLAB

MATLAB® enables you to apply supervised learning and build predictive models. You can train, validate, and tune supervised learning models with Statistics and Machine Learning Toolbox and Deep Learning Toolbox. You can combine machine learning and deep learning tools with other MATLAB toolboxes to perform industry-specific workflows. Using built-in functions and interactive apps, you can process and label data, train models, visualize model performance, and tune hyperparameters for improving model performance.

Data Preparation

MATLAB supports signal, visual, and text data. You can access and explore your data at the command line or interactively with low-code apps:

Screenshot of the Data Cleaner app used for handling outliers step in supervised learning.

Applying data preprocessing steps using the Data Cleaner app in MATLAB. (See documentation.)

For feature engineering, MATLAB provides built-in tools for most for feature extraction and feature selection methods.

AI Modeling with Low-Code Apps

The Classification Learner and Regression Learner apps help you apply supervised learning to the design, tuning, assessment, and optimization of machine learning models for classification and regression, respectively. With these machine learning apps, you can:

  • Train models on different machine learning algorithms.
  • Visualize results and evaluate model performance.
  • Compare the performance of multiple models.
  • Automatically generate code for a trained model.
  • Export a trained model to the workspace, Simulink®, and MATLAB Production Server™.

Classification Learner App

Screenshot of a supervised learning model visualized in the Classification Learner app.

Regression Learner App

Screenshot of a supervised learning model visualized in the Regression Learner app.

With the Deep Network Designer app, you can design, analyze, and modify deep learning networks interactively. You can also load pretrained networks or import networks from PyTorch® and TensorFlow.

Screenshot of a deep neural network for supervised learning created in MATLAB for supervised learning.

Designing a deep neural network using the Deep Network Designer app in MATLAB. (See documentation.)

Beyond AI modeling, with the Experiment Manager app, you can import and manage multiple machine learning and deep learning experiments, keep track of training parameters, adjust hyperparameters, analyze results, and compare code from different experiments.

Supervised Learning and Embedded AI

With MATLAB and Simulink, you can design, simulate, test, verify, and deploy AI models, built with supervised learning, that enhance the performance and functionality of complex embedded systems. Use dedicated Simulink blocks to simulate and test the integration of AI models into complex systems. Automatically generate code optimized for deployment to resource-constrained targets.