
Dan Patiño
AI Strategy & Innovation at Coderhouse
Artificial Intelligence
Supervised and unsupervised learning are the two main ways machine learning models learn from data. In supervised learning, the model trains on examples that already have the correct answer attached, called labels, and learns to predict that answer for new data. In unsupervised learning, there are no labels: the model looks for structure on its own, such as groups of similar customers or unusual transactions. The difference matters because it decides what data you need to collect, how you measure success, and which problems you can realistically solve.
This guide explains both approaches with concrete examples, compares them side by side, and gives a simple way to decide which one fits a project.
What is supervised learning?
Supervised learning maps inputs to known outputs. You give the model many examples of "this input, this correct answer," and it learns a function that generalizes to inputs it has not seen. The scikit-learn user guide groups most classic algorithms here, from linear models to decision trees and gradient boosting.
There are two main task types:
Classification: predict a category. Is this email spam? Will this customer cancel? Which of five product categories does this support ticket belong to?
Regression: predict a number. What will this house sell for? How many units will we sell next week? For a primer on the statistical side, see what regression analysis is and how analysts use it.
Supervised learning example
A subscription company wants to predict churn. It takes past customers, records features such as usage, plan, and support contacts, and labels each one "churned" or "stayed." A classifier learns from those labeled rows and then scores current customers by churn risk, so the retention team knows whom to contact first.
How supervised models are evaluated
Because the right answers are known, you can hold some labeled data back and measure how often the model is right. Classification uses accuracy, precision, recall, and the confusion matrix; regression uses error measures such as mean absolute error. The main risk is overfitting, where a model memorizes training data and fails on new data.
What is unsupervised learning?
Unsupervised learning works with unlabeled data. Instead of predicting a known answer, it describes the data: which points are similar, which are unusual, and which few dimensions capture most of the variation. The unsupervised section of scikit-learn covers the main families:
Clustering: group similar records, for example with k-means or hierarchical clustering. Common uses are customer segmentation and grouping documents by theme.
Dimensionality reduction: compress many features into a few, for example with principal component analysis (PCA), to visualize data or speed up other models.
Anomaly detection: flag records that do not look like the rest, such as possible fraud or faulty sensors.
Unsupervised learning example
An online store has purchase histories but no predefined customer types. Clustering on features such as order frequency, average basket size, and product categories might reveal groups like frequent low-spend buyers, seasonal gift buyers, and a small high-value segment. The model does not name these groups; an analyst inspects each cluster and decides whether it is meaningful.
How unsupervised models are evaluated
There is no answer key, so evaluation is harder. Teams combine internal measures, such as how compact and well separated clusters are, with business judgment: are the segments stable over time, and do they lead to different actions? A clustering that is statistically neat but useless for marketing is not a success.
Supervised vs unsupervised learning: side by side
Data: supervised needs labeled examples; unsupervised uses raw, unlabeled data.
Goal: supervised predicts a known target; unsupervised discovers structure or patterns.
Typical tasks: supervised covers classification and regression; unsupervised covers clustering, dimensionality reduction, and anomaly detection.
Evaluation: supervised compares predictions with true labels; unsupervised relies on indirect measures and human review.
Main cost: supervised often pays for labeling; unsupervised pays for interpretation.
What about semi-supervised and self-supervised learning?
Real projects often sit between the two. Semi-supervised learning uses a small labeled set plus a large unlabeled one, useful when labels are expensive. Self-supervised learning creates labels from the data itself, for example by hiding a word and asking the model to predict it. That is how large language models are pretrained on huge amounts of text, which is why modern AI depends on both ideas. The Google Machine Learning Crash Course is a good free resource for these foundations. Representations learned this way, such as embeddings, are often clustered or searched with unsupervised techniques afterward.
How to choose between them
Do you have a clear target to predict? If the business question is "will X happen?" or "how much?", it is usually supervised.
Do you have labels, or can you get them? Historical outcomes, such as past churn or past fraud cases, are labels. If none exist and labeling is too expensive, start unsupervised.
Are you exploring or deciding? Unsupervised methods are good for exploring a new dataset and generating hypotheses; supervised methods are better for repeatable decisions at scale.
Can you combine them? A common pattern is to cluster first to understand the data, then build a supervised model for a specific outcome inside one segment.
Common mistakes
Treating clusters as facts. Algorithms like k-means will always return the number of groups you ask for, whether or not real groups exist.
Leaky labels. If a feature contains information only available after the outcome, a supervised model will look great in testing and fail in production.
Skipping the baseline. Compare any supervised model with a simple rule, such as "predict the most common class," before celebrating its accuracy.
Frequently asked questions
Is ChatGPT supervised or unsupervised?
Both, in stages. Large language models are first pretrained with self-supervised learning on large text collections, then refined with supervised examples and human feedback.
Which should a beginner learn first?
Supervised learning is usually easier to start with, because you can measure whether the model is right. Clustering is a natural second step.
Is reinforcement learning a third type?
Yes. Reinforcement learning trains an agent through rewards and penalties from its own actions, which is different from learning from a fixed labeled or unlabeled dataset.
Go from ML concepts to real AI and data work
If you want to build on these foundations with live classes and feedback from practitioners, Coderhouse offers online courses with one live class per week:
AI Engineering Course: 8 weeks for experienced developers moving into AI engineering, focused on building LLM applications with retrieval, agents, evaluation, and deployment.
Data Analytics Course: 11 weeks for career switchers and data-driven professionals, covering SQL, Python, experimentation, visualization, and AI-assisted analytics.
I'm Dan Patiño, head of AI Strategy & Innovation at Coderhouse. My day-to-day work involves merging the tactical management of e-commerce (CRO, Email Marketing and SEO) with the development of disruptive solutions. I specialize in building internal AI-powered apps to automate tasks and boost innovation within the team. I firmly believe that technology is strategy's best ally. To dive deeper into my professional journey, I'll be waiting for you on my LinkedIn profile.