Skip to Content
Python: Real World Machine Learning
book

Python: Real World Machine Learning

by Prateek Joshi, John Hearty, Bastiaan Sjardin, Luca Massaron, Alberto Boschetti
November 2016
Beginner to intermediate
941 pages
21h 55m
English
Packt Publishing
Content preview from Python: Real World Machine Learning

Visualizing heat maps

Let's look at how to visualize heat maps in this recipe. This is a pictorial representation of data where two groups are associated point by point. The individual values that are contained in a matrix are represented as color values in the plot.

How to do it…

  1. Create a new Python file, and import the following packages:
    import numpy as np
    import matplotlib.pyplot as plt
  2. Define the two groups:
    # Define the two groups 
    group1 = ['France', 'Italy', 'Spain', 'Portugal', 'Germany'] 
    group2 = ['Japan', 'China', 'Brazil', 'Russia', 'Australia']
  3. Generate a random 2D matrix:
    # Generate some random values
    data = np.random.rand(5, 5)
  4. Create a figure:
    # Create a figure
    fig, ax = plt.subplots()
  5. Create the heat map:
    # Create the heat map heatmap = ax.pcolor(data, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Interpretable Machine Learning with Python

Interpretable Machine Learning with Python

Serg Masís
Large Scale Machine Learning with Python

Large Scale Machine Learning with Python

Luca Massaron, Alberto Boschetti, Bastiaan Sjardin

Publisher Resources

ISBN: 9781787123212Supplemental ContentPurchase Link