Supervised Learning
Tags: machinelearning, ai, beginners, datascience
Published: 2024-06-29 11:21:26

Imagine you're learning to play a musical instrument. In the beginning, you need constant guidance from your teacher: which note to play, how to position your fingers, what rhythm to follow. Each time you play an incorrect note, your teacher corrects you, guides you, and shows you the right way to do it. Over time, with enough practice and corrections, you become more and more skilled, capable of playing increasingly complex pieces. This is exactly what supervised learning does in the world of artificial intelligence. It's a process where an algorithm is guided and corrected at each step using pre-labeled examples. Each input is paired with the expected output, much like the advice from your music teacher. The algorithm compares its results to the expected outcomes and adjusts its model accordingly, gradually learning to perform tasks with increasing accuracy.
The main tasks involved in supervised learning are classification, regression, and prediction.

**1. Classification**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8tl1n0i8hbhocfkkmchz.png)
In the task of classification, the expected output is a category, such as "sick" or "healthy" in the medical field. This is one of the most common tasks, which is why many algorithms are available for it. The learning algorithm receives numerous examples belonging to all the categories to be predicted. Models often associate a probability, known as "confidence," with their predictions, such as "sick" at 0.27 (or 27%) and "healthy" at 0.73 (or 73%).
This probability helps refine the subsequent decisions based on a threshold: only values exceeding the set threshold are considered. By adjusting this threshold, it is possible, to some extent, to influence the rates of false positives or false negatives depending on the desired application. If there are two classes, it is called binary classification; otherwise, it is called multiclass classification. Even though the most complex cases sometimes involve thousands of classes, most practical cases require fewer than twenty classes.

**2. Classification: The Case of Images**
In the case of images, the "classic" task of classification can be refined into three distinct tasks, ordered by complexity:
**- Labeling: **This involves associating one or more labels with each image based on its content, often with a confidence score. A specific example is facial recognition, where the task is to identify individuals based on their faces.
**- Detection: **This involves indicating where in the image certain objects are located using bounding boxes. Mobile applications like Snapchat often use this to determine the location of a face in order to place elements accordingly, such as glasses on the eyes, cat ears on the head, or a cat nose on the nose.
**- Segmentation: **This involves indicating which pixel belongs to which object in the image. For example, this task is used by Kinect, the "intelligent" camera for Xbox (Microsoft), to determine the position of each part of the player's body in the image.
In the first case, the entire image is classified. In the second, the corresponding area of the image is indicated via pairs of coordinates. In the third, it amounts to applying a classification to each pixel in the image.For video, the problem becomes even more complex by adding a temporal dimension. For example, the action of writing is differentiated from the action of holding a pen by the movement of the pen on the paper over time.

**3. Regression**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/480v6npiitrkc0hgexyy.jpg)
In the task of regression, the expected output is a numerical value based on features. This differs from classification, where the output is a category from a fixed list, as here it involves predicting a real number within a specified range. This allows for predictions such as the price of a product or service, or the annual electricity consumption of a household.
However, it's important to note: while the expected results for most applications fall within two fixed bounds, the model itself typically does not enforce these limits. Post-processing of the model's results is often required to ensure they meet specific constraints. For example, in predicting the price of a product, it's necessary to verify afterward that the model's output is indeed positive. Yet, it's not feasible to directly impose this constraint on the model, which could potentially output negative.

**4. Forecasting**
The task of forecasting is a specific type of regression. Instead of using features to determine a numerical value, the goal is to predict the output based on previous values of the same variable. For example, to predict the price of a product, rather than focusing on its intrinsic characteristics (such as size, material, capabilities, etc.), the next price would be inferred from its price evolution in the past.