EZ LearnEZ Learn
Courses
EZ Board
Dashboard
All articles
ml-for-cyber-securitymlcspcat-sne

Dimensionality Reduction: Seeing What 40 Features Look Like

Humans cannot plot forty dimensions, and many algorithms perform worse as dimensionality grows. PCA and t-SNE project the same data down to two dimensions in very different ways, and this unit runs both, side by side, on the same real dataset.

Ashish Revar25 October 20265 min read

Real network and host telemetry routinely has dozens of features. Humans cannot plot forty dimensions, and many algorithms, including k-means, perform worse as dimensionality grows (the "curse of dimensionality": in high dimensions, most points end up roughly equidistant from each other, so distance stops being informative). Dimensionality reduction projects high-dimensional data down to two or three dimensions that preserve as much of the original structure as possible.

ML concept: PCA versus t-SNE

PCA (Principal Component Analysis) finds the directions of greatest variance in the data and projects onto them. It is fast, deterministic, and the projection has a precise mathematical meaning (each component is a weighted sum of the original features). t-SNE optimises a projection that preserves local neighbourhoods, often producing visually cleaner, more separated clusters, but it is slower, stochastic (a different run can look different), and its distances are not meaningful between widely separated clusters. Use PCA first, always; reach for t-SNE only when you specifically need a visualisation and do not need to reproduce exact distances.

pca_projection.py

from sklearn.decomposition import PCA

pca = PCA(n_components=2, random_state=5)
projected = pca.fit_transform(scaled_features)
print(f"Variance kept: {pca.explained_variance_ratio_.sum():.1%}")

On a real NSL-KDD-style intrusion dataset, this course's own run kept 36.3% of the variance in principal component 1 and 21.2% in principal component 2, 57.5% combined from just two numbers out of eighteen original features.

tsne_projection.py

from sklearn.manifold import TSNE

tsne = TSNE(n_components=2, perplexity=30, random_state=5, init="pca")
projected_tsne = tsne.fit_transform(scaled_features)
PCA projectiont-SNE projectionnormalDoSprobeR2L/U2R
The identical dataset, projected two ways. PCA's axes have a precise meaning (direction of maximum variance); t-SNE's do not, but its clusters often separate more cleanly to the eye

Caution: Do Not Cluster on a t-SNE Projection

It is tempting to run k-means directly on a t-SNE projection because the clusters look so clean. Resist this: t-SNE deliberately distorts distances to make local neighbourhoods visually clear, so a clustering algorithm run on its output can find clusters that are artefacts of the projection, not of the real data. Cluster on the original (or PCA-reduced) features; use t-SNE only to look at the result afterward.

Related to this topic

Continue learning

Reference material

eBook

ML for Cyber Security eBook

v1.0

Open resource

Cheatsheet

ML for Cyber Security Cheatsheet

v1.0

Open resource

MCQ Bank

ML for Cyber Security MCQ Bank

v1.0

Open resource

Question Bank

ML for Cyber Security Question Bank

v1.0

Open resource

Discussion

Loading comments…
More articlesTest your knowledge
EZ MentorAI · Free

Dimensionality Reduction: Seeing What 40 Features Look Like

Hi! I'm EZ Mentor

Your AI tutor for
Dimensionality Reduction: Seeing What 40 Features Look Like

Sign in to ask, it's free.

EZ Mentor is AI-powered · Answers may not be perfect · 10 free questions / day

EZ Learn

Structured learning across Reverse Engineering, Cloud Security and Research Methodology, plus games and practice tools. Free, and open to anyone.

Learn

  • Courses
  • EZ Articles
  • EZ Watch
  • EZ Bytes
  • EZ Talks
  • Community

Library & Exams

  • All Resources
  • eBooks & PDFs
  • Question Banks
  • Cheatsheets
  • All Exams
  • EZ Board

EZ Arena

  • EZ Games
  • Byte Rush
  • Firewall Defence
  • 3D Case Files
  • Live Quiz
  • ML Challenges

EZ Cyber Hygiene

  • Hygiene Journey
  • Cyber Safety Check
  • दिशा - Hygiene
  • सजग - Awareness
  • अभ्यास - Practice
  • Scammed? Call 1930

Platform

  • About
  • Contact
  • Events
  • Verify Certificate
  • Terms of Use
  • Disclaimer

© 2026 EZ Learn by EpochZero. Educational content for learning purposes.

Platform Lead: Ashish Revar