← Back to Tutorials Chapter 5: Models & Learning Types

Types of Machine Learning

Machine learning algorithms are broadly categorized by how they learn. Understanding these categories helps you choose the right approach for your problem. The four main types are supervised, unsupervised, semi-supervised, and reinforcement learning.

Supervised Learning

Supervised learning uses labeled training data — each example has an input and a known output. The model learns to map inputs to outputs. Common tasks include regression (predicting a number) and classification (predicting a category).

# Supervised learning example
from sklearn.linear_model import LinearRegression

model = LinearRegression()
model.fit(X_train, y_train)
predictions = model.predict(X_test)

Unsupervised Learning

Unsupervised learning finds patterns in unlabeled data. The model discovers hidden structures like clusters or groupings. Common tasks include clustering, dimensionality reduction, and anomaly detection.

# Unsupervised learning example
from sklearn.cluster import KMeans

kmeans = KMeans(n_clusters=3, random_state=42)
kmeans.fit(X)
labels = kmeans.labels_

Semi-Supervised Learning

Semi-supervised learning combines a small amount of labeled data with a large amount of unlabeled data. This approach is useful when labeling data is expensive but unlabeled data is abundant.

Reinforcement Learning

Reinforcement learning involves an agent that learns by interacting with an environment. The agent receives rewards or penalties for actions and learns to maximize cumulative reward over time. It is used in robotics, game playing, and autonomous navigation.

ML learning types comparison

Comparison of Learning Types

Type Data Goal Examples
Supervised Labeled Predict output Classification, Regression
Unsupervised Unlabeled Find patterns Clustering, PCA
Semi-Supervised Mixed Learn from few labels Classification with few labels
Reinforcement Rewards Maximize reward Game playing, Robotics

When to Use Each Type

Use supervised learning when you have labeled historical data and want to predict future outcomes. Use unsupervised learning to explore data and discover hidden patterns. Use semi-supervised learning when you have a small labeled dataset and lots of unlabeled data. Use reinforcement learning for sequential decision-making problems.

Note: Many real-world problems require combinations of learning types. For example, you might use unsupervised learning to cluster customers and then train a supervised model per cluster.

Choosing the Right Algorithm

Factors to consider: size and type of data, interpretability requirements, computational resources, and the problem's complexity. Start with simple models and increase complexity only if needed.

Summary

Understanding the four learning paradigms is essential. Each has strengths, weaknesses, and appropriate use cases. The following chapters dive deeper into supervised, unsupervised, and reinforcement learning.

Exercise 5.1: For each of these problems, determine which learning type is most appropriate: (a) predicting house prices, (b) grouping customer segments, (c) teaching a robot to walk, (d) classifying emails as spam with only 50 labeled examples and 10,000 unlabeled emails.