← AI Practitioner study path

AI and ML basics · 9 min

Regression, classification, clustering and model fit

In this lesson you will learn what question regression, classification and clustering answer, how to choose the technique a business case calls for and how to recognize overfitting, underfitting, bias and fairness.

An ML technique is the type of problem a model solves, such as estimating a number, choosing a category or finding groups. Objective 1.2.3 of the AIF-C01 exam guide asks you to choose the right technique for a and names three: regression, classification and clustering. Besides choosing the technique, the guide asks you to recognize whether a model learned well, which is what it calls fit. For example, an online store that wants to know how much it will sell tomorrow needs a different technique from the one it needs to know whether an order is fraud.

What question does each technique answer?

Three columns: regression answers how much, with the value of a house; classification answers which category, with spam or not spam; clustering answers which groups there are, with high, medium and low spending customers

Each of the three techniques answers a different type of question:

  • Regression, which answers "how much?" with a number on a continuous scale, that is, a number that can take any value, like a price with cents. The AWS example is the value of a house based on its location, its age and its number of rooms.
  • Classification, which answers "which category is it?" with an answer from a fixed set. If there are two categories ( or not spam), the classification is binary, and if there are more (cat, dog or rabbit), it is multiclass.
  • Clustering, which answers "which groups are there?" without categories defined in advance. For example, it can split customers into high, medium and low spending based on their transactions.

The three techniques are also distinguished by the type of learning they use. Regression and classification are supervised, because they need examples with the answer, while clustering is unsupervised, because it finds the groups without anyone telling it what they are. For example, the store uses regression to estimate how much money it will make in sales next week, classification to decide whether each order is fraud or not, and clustering to discover what types of customers it has.

Other problem types

The SageMaker AI table of problem types adds two cases to these three techniques:

  • Time series forecasting, which predicts a number from the history, like next month's sales. It is similar to regression, but AWS lists it as a separate problem because the data is a time series, that is, a single value measured over time.
  • Anomaly detection, which is unsupervised and alerts you when something is out of the ordinary, like a sending unusual readings. For example, it alerts the store when a customer who always buys little suddenly places a huge order.

There is also a name that causes confusion. Logistic regression, even though it has "regression" in its name, predicts a category, and the AWS example is predicting whether a student passes or fails based on how many times they logged in to the online course.

cloud path tip: if you see "logistic regression" in a question, think classification.

Match each case with its technique

0 of 4 pairs

Tap a case and then the technique that solves it.

0 of 4 pairs.

What is model fit?

Three charts: underfitting, with a line that is too simple and doesn't follow the points; good fit, with a straight line that follows the trend of the points; overfitting, with a line that goes through every point

Fit is how well the model adapts to the data. AWS explains it as a spectrum, that is, a scale that runs from one end to the other, with good fit in the middle and an error at each end. For example, a store model with good fit is right almost as often with the orders it learned from as with the new orders that come in every day.

Overfitting

Overfitting is the end where the model gets the training data right and fails with new data, because it memorized the examples, included. In the AWS example, a model that learns to recognize dogs from photos taken almost all in parks can learn that grass means "dog", and then it doesn't recognize a dog inside a house.

Overfitting happens with little data, with very noisy data or with a model that is too complex. It is detected by testing the model with data it hasn't seen, and it is corrected with more data or with a less flexible model, that is, a simpler one.

Underfitting

Underfitting is the opposite end, where the model is too simple or was trained too little and fails with both the training data and new data. It is often corrected by training more passes over the data, which are called epochs. For example, a model that estimates the store's sales as if the same amount were sold every day fails with the days it already knew and also with new ones, because it ignores that weekends or sales events change how much is sold.

AWS sums up each end in one word: underfitting has high bias and overfitting has high . That is why, when an option says "high bias", it is talking about underfitting, and when it says "high variance", it is talking about overfitting.

Overfitting or underfitting?

0 of 4

Tap the correct column for each model.

  1. It is right 99% of the time with the training data and 60% with new data

  2. It is right 55% of the time with the training data and 54% with new data

  3. It was trained with 200 photos and it is a very complex model

  4. The team corrects it by training more epochs

Bias and fairness

The word "bias" has two meanings on the exam. The first belongs to fit, where high bias means underfitting, which is a fit error: the model holds on to an idea of the data that is too simple.

The second meaning is AI bias, which AWS defines as a wrong assumption in the model that produces results that don't reflect reality. This bias almost always comes from the training data, and the AWS example is a diagnostic service that gets a group of people wrong because its data didn't have enough patients from that group.

Fairness is tied to this second meaning. It is one of the dimensions of AWS and consists of considering the impact of the system on different groups of people, and domain 4 of the exam develops both ideas. For example, if almost all the purchases the store's fraud model learned from belong to young customers, it may flag more normal purchases by older customers as suspicious, and looking after fairness means checking that this doesn't happen.

What risk does it have?

A model that approves loans was trained only with applications from one city, and it is now used across the whole country. What risk best describes the problem?

On the exam

In a techniques question, look for what type of answer the company wants: a number (regression), a category (classification), groups nobody defined (clustering) or whatever is out of the ordinary (anomaly detection).

In a fit question, compare how the model does with the training data and with new data. If it does well with the training data and badly with new data, it is overfitting, and if it does badly with both, it is underfitting. For example, if a question says that a model is right almost every time in the team's tests but fails a lot with real customers, it describes overfitting.

Review question

A team trains a model to detect defective parts in a factory. With the training images it is right 98% of the time, but on the production line it is only right 70% of the time. What best describes the problem?

Next

  • What is overfitting?, the AWS page with the example of the dog and the grass.
  • Take a practice exam at /examenes and review your result in domain 1.