Course materials · Introduction to Machine Learning

Matplotlib

English translation

Learning objectives

The same numbers reveal different relationships depending on the graph. Distinguish changes over time from comparisons across categories.

Graphs Suited to the Representation

Starting conditions

t=[01234]t=\begin{bmatrix}0&1&2&3&4\end{bmatrix}, temperature=[20,21,23,22,24] °C.

Procedure

  1. Display the same data as a line plot and a bar chart.
  2. Use actual values to explain which representation makes trends or values at specific times easier to read.

Results to retain

import numpy as np
import matplotlib.pyplot as plt
t=np.arange(5);temp=np.array([20,21,23,22,24])
plt.plot(t,temp,'o-');plt.xlabel('Time [s]');plt.ylabel('Temperature [C]');plt.grid()

Record results and self-check

Representation:

Observed facts:

Times and values used:

Suitable purpose:

Points to check

Comparing Two Measurements

Starting conditions

Add the second sensor's data [19,21,22,23,23] and compare on the same axes.

Procedure

  1. Associate the second sensor values [19,21,22,23,23] with the same times 0,1,2,3,40,1,2,3,4, and plot them on the same axes in the same Figure as the first sensor.
  2. Use a legend to distinguish the two sensors. Record time, first sensor value, second sensor value, and first minus second in five rows.
  3. Find and explain the times when the two sensors agree and differ most, using the table and plots.

Results to retain

temp2=np.array([19,21,22,23,23])

Record results and self-check

Time:

First sensor value:

Second sensor value:

First − second value:

Points to check

Checking Other Inputs

Starting conditions

Plot the same two sensors' data as a scatter plot, and compare interpretations when time order is removed.

Procedure

  1. Pair the two sensors' values at each time and create a scatter plot with the first sensor on the x-axis and the second on the y-axis. Use the same data as the preceding time plot.
  2. Label each point with its time to identify the sample. Explain the relationship between the two sensors visible in the scatter plot separately from the sequence of changes that cannot be inferred without time labels.

Results to retain

# Use the preceding activity's data and functions to check the specified new examples.

Record results and self-check

The two scatter plot axes:

Correspondence between times and points:

Visible relationship between the two sensors:

Interpretation of changes over time:

Points to check