liveBook · Manning

Dimensionality reduction

As explained in Cyber Threat Hunting

Dimensionality reduction transforms data into a representation with fewer features while retaining important information.

Dimensionality reduction transforms data into fewer features while retaining important information. It addresses strongly correlated features by replacing them with compact composite features, making machine-learning data easier to model and visualize. section 9.2.4 section 9.2.5

Apply principal component analysis (PCA) through a repeatable preparation workflow:

  • Inspect feature relationships with a Pearson-correlation heat map and identify highly correlated columns. section 9.2.4
  • Scale the training features with StandardScaler so each feature has mean zero and standard deviation one. section 9.2.5
  • Plot cumulative explained variance and retain components near the curve’s leveling-off point. section 9.2.5

Reducing DNS-derived features

A DNS feature set contains strongly correlated measurements such as fqdn_length, first_fqdn_label_length, and max_fqdn_label_length. After scaling, PCA combines correlated features into independent components; selecting four components produces X_train_pca with PC1 through PC4, while plotting PC1 and PC2 supports visual inspection. section 9.2.4

Listing 9.17 Plotting the PCA cumulative sum of the explained variance
from sklearn.decomposition import PCA                               #1
import numpy as np                                                  #2
 
pca=PCA().fit(X_train_scaled)                                       #3
plt.figure()                                                        #4
plt.plot(np.cumsum(pca.explained_variance_ratio_))                  #5
plt.xlabel('Number of principal components')                        #6
plt.ylabel('Cumulative explained variance')                         #7
plt.show()                                                          #8

Use the cumulative explained-variance plot to compare component counts before choosing the reduced representation. section 9.2.5

How Cyber Threat Hunting covers it

How deep it goes
Explains PCA operationally through scaling, variance-based component selection, transformation, and two-dimensional plots, while deferring mathematics.
Examples
Uses DNS-derived FQDN features, Pearson-correlation heat maps, four principal components, and class-colored PC1–PC2 and PC3–PC4 plots.
What it assumes
Assumes familiarity with feature tables and supervised learning while demonstrating feature selection, train-test splitting, and scaling.
What you can do after
Apply it via scikit-learn by scaling training features, selecting components from explained variance, and transforming data with PCA.
How it connects
Connects PCA with feature scaling, correlation analysis, principal components, explained variance, supervised learning, and data visualization.

Also explained in

Compare how 11 books explain dimensionality reduction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Cyber Threat Hunting. The section links point to the parts of the book it draws on.