machine learning
high dimensional data
decision boundary
data visualization
dimensionality reduction

Plotting decision boundary for High Dimension Data

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Understanding Decision Boundaries in High-Dimensional Spaces

Decision boundaries play a critical role in classification problems across various fields of data science and machine learning. They serve as the demarcation line or surface which effectively separates data points of different classes. When dealing with low-dimensional data (R2\mathbb{R}^2 or R3\mathbb{R}^3), visualization of these boundaries is relatively straightforward. However, challenges arise when we escalate to high-dimensional spaces often encountered in real-world datasets. This article explores strategies and methodologies for constructing and visualizing decision boundaries in high-dimensional data.

Technical Explanations

In classification tasks, the decision boundary is defined mathematically as a function that maps feature space X to output space Y. For binary classification, this is often a hyperplane:

f(x)=wx+b=0f(\mathbf{x}) = \mathbf{w} \cdot \mathbf{x} + b = 0

where $\mathbf\{w\}$ and $\mathbf\{x\}$ are vectors of weights and data features, respectively, and bb is a bias term.

In high-dimensional spaces (Rn\mathbb{R}^n where n>3n > 3), the hyperplane becomes increasingly difficult to visualize. Let’s delve into some common approaches utilized to manage and effectively plot decision boundaries amidst these complexities.

Dimensionality Reduction Techniques

  1. Principal Component Analysis (PCA): • PCA reduces the dimensionality of the data while retaining core variance features. By projecting high-dimensional data onto a lower-dimensional subspace, typically R2\mathbb{R}^2 or R3\mathbb{R}^3, we are able to visualize decision boundaries more easily.
    Pros: PCA preserves global structures of data distributions. • Cons: May lose significant discriminative power when reducing dimensions.
  2. t-Distributed Stochastic Neighbor Embedding (t-SNE): • t-SNE is a non-linear dimensionality reduction technique adept for visualizing high-dimensional data. It converts similarities between data points to joint probabilities and seeks to minimize the divergence between these probabilities in reduced space.
    Pros: Well-suited for visualization of clusters and can reveal hidden structures in data. • Cons: Does not preserve global data structure, making decision boundary utility limited to local classifications.

Projection Techniques for Visualization

Once dimensionality reduction is completed, several visualization techniques can be applied:

Contour Plots: • After reducing dimensions, contour plots can be utilized to visualize decision boundaries. Contour plots work well when the reduced data is in two dimensions.

3D Plots: • For R3\mathbb{R}^3 space, 3D visualizations like scatter plots with transparent plane surfaces can be effective.

Example Code

Below is a simplified example using Python with `matplotlib` and `scikit-learn` for visualizing decision boundaries using PCA:


Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.