Concepts / Preprocessing for Supervised Algorithms

Preprocessing for Supervised Algorithms

Unsupervised learning can also serve as a preprocessing step, where a new representation of the data is passed to a supervised algorithm.

  • Programming

Two Jobs for Unsupervised Learning

Unsupervised learning is easy to describe in the abstract, but a working data scientist usually asks a more practical question: what are these methods actually for? In practice, unsupervised algorithms appear in two main roles. The first is as a tool for looking at data itself, helping a person build an understanding of what a dataset contains. The second is as a helper inside a larger pipeline, where the output of an unsupervised step feeds into a supervised algorithm.

This article walks through both roles, follows a single hypothetical scenario through them, and ends with the pitfalls that catch people out. The central idea to keep in mind is that the second role depends on a new representation of the data, and that a new representation can change how well a supervised algorithm performs, sometimes for the better and sometimes not at all.

Exploring Data With an Unsupervised Lens

Definition

Unsupervised algorithms are often used in an exploratory setting, where a data scientist wants to understand the data better rather than run them inside a larger automatic system.

A large share of unsupervised work happens in this exploratory setting. The goal is not to hand a decision to an automated system. Instead, the unsupervised algorithm acts as a lens: it helps a person see structure in the dataset, and the results inform that person's judgment about the data. This is why these methods are typically used on their own rather than as one component of a larger automatic system.

Comparing the Two Roles

The same family of algorithms can play two quite different parts. The table below contrasts the exploratory role with the preprocessing role, so you can tell which one you are looking at in a given project.

AspectExploratory usePreprocessing use
Main goalUnderstand the data betterProduce a new representation for a supervised algorithm
Who uses the resultThe data scientist, to inform judgmentThe supervised algorithm inside a pipeline
Typical setupUsed on its ownOne component of a larger pipeline
Where the output goesTo a person reading itForward into the supervised step

Two roles for an unsupervised algorithm

The Unsupervised Step as Preprocessing

The second common application treats an unsupervised algorithm as a preprocessing step. Rather than feeding the raw data straight into a supervised algorithm, the pipeline first passes the data through an unsupervised step that learns a new representation of it. The supervised algorithm then works with this transformed version of the data.

The flow of information is what matters here. The data enters in its original form, the unsupervised step reshapes it, and the reshaped data is what the supervised algorithm learns from. The diagram below shows that movement from left to right.

Raw dataoriginal formUnsupervised steplearns a new representationNew representationtransformed dataSupervised algorithmlearns from transformeddatapasses datareshapesis passed to
How does data move from the raw input through the unsupervised step into the supervised model, and what gets passed between them?

Notice what gets passed between the steps. The unsupervised step does not hand the supervised algorithm the raw data; it hands over the new representation. That representation is the only thing the supervised algorithm sees from this stage onward.

Tracing One Dataset Through the Pipeline

Worked example

A hypothetical dataset passed through a preprocessing step

A data scientist has a dataset of records with many descriptive features and wants a supervised algorithm to learn from them. They consider adding an unsupervised step first, so the supervised algorithm learns from a new representation instead of the raw features.

  1. 1
    Start with the raw data

    The records enter the pipeline in their original form, with the original features.

  2. 2
    Pass the records through the unsupervised step

    The unsupervised step learns a new representation of the same records. The data is reshaped, not discarded.

  3. 3
    Feed the new representation to the supervised algorithm

    The supervised algorithm learns from the transformed version of the data, not from the raw features.

  4. 4
    Measure each outcome separately

    Compare accuracy, memory use, and time use against a run on the raw data. Each one is measured on its own, because none of the gains is guaranteed.

Result

The extra step is only worth keeping if the measurements show a benefit. Adding the unsupervised step does not by itself promise a better model.

The before and after view below makes the change concrete. The unsupervised transform takes the features in their original form and produces a new representation, which is what the supervised algorithm then receives.

Raw featuresoriginal formNew representationlearned by unsupervisedstepunsupervised transform
How does the same dataset look different before and after the unsupervised transform?

What do you think happens?

After adding the unsupervised step, will the supervised model always become more accurate?

  • Yes, the new representation always improves accuracy

  • No, accuracy gains are not guaranteed

  • Only if the dataset is very large

Reveal answer
Answer:

No, accuracy gains are not guaranteed

The source says a new representation can sometimes improve the accuracy of supervised algorithms, but neither accuracy nor resource savings is guaranteed to appear. The only safe approach is to measure the result.

Accuracy, Memory, and Time Trade-offs

The reason to add an unsupervised step to a supervised pipeline is that a new representation can change how well the supervised algorithm performs. The source identifies two kinds of benefit. One is accuracy. The other is resource use, which covers memory and time consumption.

OutcomeWhat a new representation can doHow to evaluate it
AccuracySometimes improves the accuracy of the supervised algorithmCompare the supervised model's accuracy on the raw features and on the new representation
Memory useCan lead to reduced memory consumptionMeasure memory for the raw-data run and the transformed-data run separately
Time useCan lead to reduced time consumptionMeasure time for the raw-data run and the transformed-data run separately

Three outcomes to measure separately

Order of Steps in a Pipeline

A pipeline is a sequence, and the order of its steps determines what each step is given. The sequence diagram below shows the messages passed in order: the dataset goes to the unsupervised step, and the new representation goes on to the supervised algorithm.

Datasetoriginal formUnsupervised steplearns representationSupervised algorithmlearns from representationraw datanew representation
In what order do the data and the new representation move between the steps?

Mistakes That Catch People Out

The source notes that the practical pitfalls are where people usually get caught. The following mistakes come up when unsupervised methods are applied in practice.

  • Common mistake

    Assuming a new representation always improves accuracy

    What it looks like

    Adding an unsupervised step and expecting the supervised model to score higher without ever checking.

    Why it fails

    A new representation can sometimes improve accuracy, but the gain is not guaranteed.

    Do this instead

    Measure the supervised model's accuracy on the raw features and on the new representation, then compare the two.

  • Common mistake

    Treating memory and time savings as automatic

    What it looks like

    Concluding that a pipeline is efficient because it feels faster, without a measurement.

    Why it fails

    Resource savings are separate from accuracy and are not guaranteed to appear at all.

    Do this instead

    Measure memory and time separately for the raw-data run and the transformed-data run.

  • Common mistake

    Bundling the accuracy and resource results together

    What it looks like

    Reporting that the transformed version is better overall after measuring only one of the outcomes.

    Why it fails

    Accuracy and resource use are separate outcomes, so a benefit in one says nothing certain about the other.

    Do this instead

    Report each outcome on its own, with its own measurement.

  • Common mistake

    Using an exploratory result as an automatic decision

    What it looks like

    Feeding the output of an exploratory analysis straight into another system without a person reviewing it.

    Why it fails

    Exploratory use is meant to inform a person's judgment about the data rather than run inside a larger automatic system.

    Do this instead

    Keep a person in the loop when the goal is understanding the data, and treat the output as input to judgment.

  • Common mistake

    Leaving the comparison setup unclear

    Why it fails

    If it is not clear what each step was given, a measured difference cannot be attributed to the representation itself.

    Do this instead

    Write down the data each step sees before comparing results.

Applying the Pipeline Reasoning

MEDIUM

A colleague says their new representation made the supervised model both more accurate and faster, so the unsupervised step must be worth keeping. Which claim in this statement needs its own separate measurement, and why?

Hints
  • Think about whether accuracy and resource savings are the same outcome.
  • Recall what the source says about whether these gains are guaranteed.
  • Ask whether the colleague measured each outcome on its own.

Key Takeaways

  • Unsupervised algorithms are often used in an exploratory setting, where the goal is to help a data scientist understand the data, and their output informs human judgment.
  • Unsupervised learning can also be a preprocessing step: the raw data is reshaped into a new representation, and the supervised algorithm learns from that representation.
  • A new representation can sometimes improve the accuracy of supervised algorithms and can lead to reduced memory and time consumption, but neither outcome is guaranteed.
  • Accuracy and resource savings are separate outcomes and should be measured separately, and the order and inputs of each pipeline step should be clear before results are compared.

Related concepts

More concepts starting with P