You will learn: most-used supervised learning algorithms such as linear regression, logistic regression, SVM, and decision trees.
Linear regression is a supervised machine learning algorithm where the predicted output value keeps a linear (continuous) relationship with the input.
One simple application of linear regression can be used to predict the economic activity of a country in relation to its population.
Figure 1: The regression line represents the continuous range of values between GDP as economic activity measurement and population associated.
We can distinguish between two types:
- 1.Simple regression
When just considering a single variable as input data, the linear regression line can be expressed with an equation of the form:
are the weights our algorithm will try to “learn” to provide the most accurate predictions
represents our input data and
represents our prediction.
Given Example 1, linear regression would let us predict the economic activity (
) from the number of people (
). For instance, for a region with 30 million people, the expected GDP value would be about $1,400 billion.
The same inverse logic could be applied if trying to predict the population (
) from its economic activity (
). In that case, we would reverse the regression equation to:
- 1.Multi-variable regression
Following the same idea, if several variables play a role in the linear prediction, multiple weights
will apply to each variable in the following form:
where this time
are the coefficients the algorithm will try to “learn” to provide the most accurate predictions given
as input data.
In Example 2, we can still predict the sales of a company given the number of employees, investment in R&D and income as follows:
In order to find the best weights
that minimizes the error between the model's predictions from its ground-truth labels, we must introduce the concept of a loss value. We could describe it as the absolute difference between the true value and the predicted one.
When this measurement is applied to a set of evidence, we call it loss function (or cost function). It can be understood as a measurement of how "good" your model is: the lower the loss, the better your model is.
For linear regression models, we typically use Mean Squared Error (MSE) as a loss function:
is the total number of samples.
To find the value of the parameters that minimize the cost function, there is a closed-form solution — in other words, a mathematical equation that gives the result directly. This is called the Normal Equation.
Logistic regression is another supervised learning method to classify samples by assigning a discrete set of classes.
Similarly, as linear regression makes predictions on continuous number values, logistic regression uses a logistic Sigmoid function as a prediction value associated with multiple variables of the form:
The logistic curve of the sigmoid function for which outputs are between 0 and 1. This property allows the regression to provide a probability value.
The logistic curve of the Sigmoid function for which outputs are between 0 and 1. This property allows the regression to provide a probability value.
We can distinguish between three types:
- 1.Binary classificationThis regression type only considers situations in which the observed outcome for a dependent variable only takes two types. As an example, we might use logistic regression to classify lung cancer as benign or malignant.
- 2.Multi-class classificationIn this second case, the outcome can be presented as three or more types. An example case could be predicting the type of lung cancer as e.g. "cancer A", "cancer B", or "cancer C".
- 3.Ordinal classificationSame idea as in (2) Multi-class classification, but this time the predictions are ordered with a sense of positioning. An example case could be a restaurant service rating choice among "poor", "fair", "good", and "excellent".
Support vector machines (SVMs) are a set of supervised machine learning algorithms for classification, regression, and outlier detection that are built around hyperplane separation of the data. In a two dimensional space, this separation can be understood as a simple decision boundary in the form of a line, but SVMs are also effective in high dimensional spaces.
Scikit-learn's SVM for a three class classification example.
Thanks to their great adaptation to multidimensional spaces, SVMs are often used for Natural Language Classification problems.
Decision trees are non-parametric supervised machine learning techniques that are able to make predictions by learning simple decision rules encoded in a flowchart-like structure.
These tree structures are easy to represent and interpret. Leaves on the tree represent classifications labels, non-leaf nodes are features, and branches represent conjunctions of features that lead to the classifications.
An example of a decision tree with the objective of predicting if the weather is good or not for a hike. Source: https://www.sciencedirect.com/topics/computer-science/decision-trees
When grouping multiple decision trees together, we refer to this ensemble of models as random forests.