Memuat
Memuat
Want to go deeper?
Join one of our courses or ask us directly on WhatsApp.
Picked from the software, topic, and level of “Class Machine Learning Python #14: Dimensionality Reduction: PCA, t-SNE & UMAP”.
Other ways we can help with Python.
Learn with a mentor
Scheduled AI & Machine Learning courses with live guidance and a certificate.

Multi-Objective Optimization Course: NSGA-II, MOPSO & Hybrid Algorithms (Python)

ECG Arrhythmia Classification Course with Wavelet & Deep Learning (PyTorch)

ANFIS + PSO/GA Course for Non-Linear Time Series Forecasting (Python)
Have it built for you
No time to learn Python? Our team can do the project for you.

Python Machine Learning — Prediction Models, Customer Segmentation, Fraud Detection & AI Apps

AI Image Creation with Stable Diffusion — Unlimited Custom Visual Production
★ 4.9

AI Image & Video Creation with Leonardo AI — All-in-One Visuals for Business
★ 4.9
Get notified about new Python classes
At most one email a week. Unfollow anytime with one click.
The full narration of this video. The current sentence is highlighted while the video plays; click any sentence to jump there.
This is the final result, 1,700 handwritten digit images, each with 64 dimensions, mapped into points on a 2-dimensional plane by PCA, t-SNE, and UMAP. See how the same digits cluster together to form islands. Let's get started. Welcome to episode 14 of the Machine Learning with Python series. Real data often has tens to thousands of features. We can't visualize them, models become slow, and there are often repeated features. Dimensionality reduction summarizes many features into a few new features, while preserving as much information as possible. We learn PCA for compression, as well as t-SNE and UMAP for visualization.
We create a file called pca.py. The data is the digits dataset, each image of a digit is 8x8 pixels, so 64 features. PCA finds new directions, called principal components, that capture the largest variation in the data. We calculate explained variance, which is the percentage of information stored by each component, then we plot the cumulative sum. It turns out that about 20 components already store 90% of the information.
PCA can also be used for compression. We summarize the images into 5, 15, and 40 components, then reconstruct them with inverse transform. With 5 components, the digits are still blurry. With 15 components, the digits are already readable, even though the data is only a quarter of the original.
Does compression damage model performance? We train logistic regression with the original 64 features and with 20 PCA components. Accuracy only drops slightly, even though the number of features is less than a third, so training is faster.
Now visualization. Create a file called map.py. We reduce 64 dimensions into 2 dimensions with 3 methods. PCA is a fast linear method. t-SNE and UMAP are non-linear methods that focus on keeping nearby neighbors close together. We also recorded the processing time. First install UMAP using pip install umap-learn. See the results.
In PCA, many numbers are still overlapping. In TSNE and UMAP, each number forms a distinct island. Numbers that are similar in shape. Like 3, 5, and 8. They are located close to each other. In this small dataset, UMAP is slower due to the initial compilation. But for very large data, UMAP is usually much faster than TSNE. Remember, TSNE and UMAP are for visualization. While PCA is suitable for compression and preprocessing models.
Done. We have learned PCA and X-Planet Variance, image compression, PCA before the model, as well as visualizing high-dimensional data with TSNE and UMAP. In the next episode, we will learn anomaly detection to find suspicious transactions, and market basket analysis. Want to master machine learning and data science? Cerdas Inovasi Digital offers Python, machine learning, and AI courses from the basics, model prediction services, data analysis, and AI application development for business and research, as well as selling complete source code of this tutorial. Want to master the entire series, from machine learning introduction to deploying models to the web? All 18 episodes, complete with step-by-step PDF guides, are available to premium tutorial subscribers. Subscribe starting from Rp69.000 per month Save 28% with the 12-month package, or one-time payment of Rp999.000 for lifetime access. Want a single class only? Buy single classes with lifetime access. Subscribe now on the premium page cerdasinovasidigital.com Contact us via WhatsApp, or visit cerdasinovasidigital.com Thank you for watching, See you in the next episode.
Type a question or keyword; we find the part of this episode that explains it and jump the video there.
Notes are saved with the current video time and are only visible to you.
Stuck on a step? Ask here; the instructor and other learners can answer.
No questions yet.

Cerdas Inovasi Digital Team
Software developers, BIM & 3D engineers, and AI practitioners
We build software, BIM models, games and AI automations for clients every day, and turn that hands-on work into step-by-step classes: every step is shown on screen and comes with a PDF guide you can keep.
See our clients →