Machine Learning Explained: Supervised, Unsupervised and Reinforcement Learning

A clear introduction to machine learning — supervised, unsupervised and reinforcement learning, common algorithms, the ML workflow, and how classic ML relates to deep learning and LLMs.

By Danyal Ahmed - Data Scientist · · 5 min read

Machine learning is the practice of building systems that learn patterns from data instead of following hand-written rules. A spam filter trained on labeled emails, a model forecasting next week's demand, and a recommendation engine all work this way. This guide explains the main types of machine learning, the algorithms you'll meet most often, and how a real ML project runs.

Key takeaways

  • Supervised learning learns from labeled examples to predict outputs: classification and regression.
  • Unsupervised learning finds structure in unlabeled data: clustering, dimensionality reduction, anomaly detection.
  • Reinforcement learning learns by trial and error from rewards.
  • For tabular business data, gradient-boosted trees are often the strongest classic approach. Deep learning dominates images, audio and text.
  • Most ML effort goes into data, features, evaluation and deployment, not choosing algorithms.

Rules vs learning

Traditional programming: rules + data → answers. Machine learning: data + answers → rules (a model), which you then apply to new data.

Machine learning is worth it when rules are too complex to write by hand (recognizing handwriting), change often (fraud patterns) or need to be personalized at scale (recommendations).

Supervised learning

You provide input features and the correct label for many examples; the model learns the mapping.

Classification: predicting a category

  • Will this customer churn? (yes/no)
  • Is this transaction fraudulent?
  • Which support queue should this ticket go to?

Regression: predicting a number

  • What will this house sell for?
  • How many units will we sell next week?
  • What's this customer's expected lifetime value?

Common algorithms

Algorithm Good for Notes
Linear / logistic regression Baselines, interpretability Fast, explainable, assumes simpler relationships
Decision trees Interpretable rules Prone to overfitting alone
Random forests Robust general-purpose models Ensemble of trees; little tuning needed
Gradient-boosted trees (XGBoost, LightGBM, CatBoost) Tabular data Often top performers on structured data
k-nearest neighbors Simple similarity-based prediction Slow at scale; sensitive to feature scaling
Neural networks Images, text, audio, very large datasets Needs more data and compute
pythonfrom sklearn.model_selection import train_test_split
from sklearn.ensemble import HistGradientBoostingClassifier
from sklearn.metrics import classification_report

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, stratify=y, random_state=42)
model = HistGradientBoostingClassifier(max_iter=300, learning_rate=0.05)
model.fit(X_train, y_train)
print(classification_report(y_test, model.predict(X_test)))

Unsupervised learning

No labels. The model finds structure on its own.

  • Clustering: group similar items, such as customer segments or topic groups in support tickets (k-means, DBSCAN, hierarchical clustering).
  • Dimensionality reduction: compress many features into fewer while preserving structure, for visualization or as model input (PCA, UMAP).
  • Anomaly detection: flag unusual observations, such as suspicious logins or faulty sensors (isolation forests, statistical methods).
  • Association rules: "customers who buy X often buy Y".

Unsupervised results need human interpretation. The algorithm will always find clusters; whether they're meaningful is a business judgment.

Reinforcement learning

An agent takes actions in an environment and receives rewards, learning a policy that maximizes long-term reward. It's known for game-playing systems and robotics, and it's used in recommendation, bidding and resource allocation. It's also part of how LLMs are aligned with human preferences (how LLMs work).

RL is powerful but data-hungry and tricky to get right. Most business problems are better served by supervised learning or simpler bandit algorithms.

Semi-supervised and self-supervised learning

  • Semi-supervised: a small labeled set plus a large unlabeled set.
  • Self-supervised: the data provides its own labels, as with predicting masked or next words. This is how foundation models, including LLMs and embedding models, are pre-trained.

Deep learning and where it fits

Deep learning uses neural networks with many layers to learn features automatically from raw data. It excels at unstructured data: images, audio, video and text. For typical tabular business data (rows and columns from your database), gradient-boosted trees often match or beat deep learning with far less effort.

Today, many text and image problems are solved not by training models from scratch but by using pre-trained foundation models, through prompting, embeddings or fine-tuning (fine-tuning vs RAG vs prompting).

The machine learning workflow

  1. Frame the problem. What decision will the model support? What's the prediction target? How will success be measured in business terms?
  2. Collect and understand data. Sources, quality, biases, leakage risks (data cleaning with pandas).
  3. Engineer features. Often the biggest driver of performance (feature engineering guide).
  4. Split data properly. Train, validation and test sets, respecting time order for temporal data.
  5. Train baselines, then better models. Start simple, since a logistic regression baseline tells you whether complexity is buying anything.
  6. Evaluate with the right metrics (classification metrics explained) and check for overfitting (bias-variance trade-off).
  7. Deploy as a batch job or real-time service.
  8. Monitor for drift and degradation, and retrain as needed (MLOps explained).

Common pitfalls

  • Data leakage: features that contain information unavailable at prediction time, like "account closed date" in a churn model. It produces amazing test scores and useless production models.
  • Optimizing the wrong metric: 99% accuracy on a dataset with 1% fraud is achieved by predicting "not fraud" every time.
  • Ignoring the baseline: complex models that barely beat a simple heuristic.
  • Training/serving skew: features computed differently in training and production.
  • No plan for monitoring: models decay silently as the world changes.

Is machine learning the right tool?

Ask:

  • Is there a clear prediction that supports a decision?
  • Is there enough historical data, with labels where needed?
  • Would a simple rule get 80% of the value?
  • Can you act on predictions and measure the impact?

If the answers are yes, no, no, yes, machine learning may be overkill. If they're yes, yes, no, yes, it's probably worth building.

FAQ

What is the difference between AI and machine learning?

AI is the broad goal of making machines perform tasks that require intelligence. Machine learning is the dominant approach to achieving it: learning from data. Deep learning and LLMs are subsets of machine learning.

How much data do I need for machine learning?

It depends on problem complexity and the algorithm. Simple tabular models can work with thousands of labeled examples; deep learning from scratch typically needs far more. Pre-trained models reduce data needs dramatically for text and image tasks.

Which machine learning algorithm is best?

There's no universal best. For tabular data, gradient-boosted trees are a strong default; for images, audio and text, pre-trained neural networks dominate. Always compare against a simple baseline on a proper validation set.

Do I need a GPU for machine learning?

Not for most classic ML on tabular data; CPUs handle it well. GPUs matter for training deep learning models and running large models locally.