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 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 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 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 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.
| 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 |
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.
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.
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.