liveBook · Manning

Heat map

As explained in Data-Driven Cybersecurity

A heatmap is a matrix or spatial visualization that encodes values using color intensity.

A heat map uses color intensity to make values in a table easier to compare. In security analytics, it can reveal relationships in login data or show where a classifier makes mistakes. The color draws attention; the underlying values still determine the interpretation. section 11.4 section 12.4.1

Read the cells according to what the map measures:

  • A correlation heatmap displays values from −1 to 1. Compare login hour with failed login attempts to investigate whether failures tend to increase at particular times; a strong relationship can prompt a review of authentication controls. section 11.4
  • A grayscale confusion-matrix heatmap displays classification counts. Darker cells contain higher counts: diagonal cells are correct predictions, while off-diagonal cells reveal errors needing attention. section 12.4.1
  • On a security analyst dashboard, a heatmap can show real-time alert counts by severity, helping analysts see where attention may be needed. section 2.2.3

Check a risk classifier

For articles classified as high or low risk, compare the true labels in the confusion matrix’s rows with predicted labels in its columns. An off-diagonal dark cell makes a recurring type of misclassification visible, rather than hiding it within an overall performance figure. section 12.4.1

Listing 11.1 Hidden relationships
#Import libraries
import seaborn as sns  #1
import pandas as pd  #2
import matplotlib.pyplot as plt  #3

#Example dataset: Login hours and failed attempts
data = {'Login_Hour': [8, 9, 10, 11, 12, 13, 14, 15,
                       16, 17, 18, 19, 20, 21, 22, 23, 
        0, 1, 2, 3],  #4
        'Failed_Login_Attempts': [2, 3, 4, 5, 3, 6, 7, 5, 
    8, 9, 12, 13, 10, 8, 7, 
    5, 2, 3, 4, 5]}  #5

df = pd.DataFrame(data)  #6

#Calculate correlation matrix
correlation_matrix = df.corr()  #7

#Plot heatmap
plt.figure(figsize=(8, 6))  #8
sns.heatmap(correlation_matrix, annot=True,
            cmap='Grays', cbar=True)  #9
plt.title('Correlation Between Login Hours and Failed \
          Login Attempts')  #10
plt.show()  #11

The Python listing builds a correlation matrix from synthetic login-hour and failed-attempt data, then plots it with annotated cells using seaborn. section 11.4

Use the pattern to decide what to investigate or report, not as a decision by itself. In a stakeholder report, pair a heat map with a concise explanation of the trend or area needing attention. section 11.4 section 3.2.4

How Data-Driven Cybersecurity covers it

How deep it goes
Works through correlation plotting and explains confusion-matrix cells, but does not detail heatmap construction beyond plotting calls.
Examples
Uses synthetic login-hour and failed-attempt data alongside high- and low-risk article classification.
What it assumes
Starts with synthetic data requiring no preprocessing and explains correlation values and confusion-matrix cells.
What you can do after
Apply it via pandas and seaborn to plot login correlations, and evaluate/understand classification errors in a grayscale confusion matrix.
How it connects
Links correlation matrices to login analysis and confusion matrices to classification evaluation.

Also explained in

Compare how 7 books explain heat map →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Driven Cybersecurity. The section links point to the parts of the book it draws on.