Always free. For everyone.
Course outline
Module 09 of 20 · Data science

See patterns and uncertainty

Build honest charts, compare summaries, and show how uncertain an estimate can be. This module has 3 lessons and takes about 1h 15m. Each lesson has a practice exercise that runs real Python in your browser and a short quiz.

Start module 09 in the Learning Lab
LESSON 1 OF 3

Choose a chart that answers a question

25 minEnergy
WHAT YOU WILL DO

Plot a synthetic solar generation profile with meaningful axis labels.

A line chart shows how a measurement changes over ordered time. Put the time on the horizontal axis and energy or power on the vertical axis. Include units so a reader does not confuse kW, which measures power, with kWh, which measures energy.

plt.subplots() creates a figure and axes. Call methods on the axes to add the line, labels, and title. Use a scatter plot for the relationship between two numeric variables and a bar chart to compare categories.

See it in action

example.pyPython 3
import numpy as np
import matplotlib.pyplot as plt

# Synthetic hourly solar power, in kW.
hour = np.array([6, 8, 10, 12, 14, 16, 18])
power_kw = np.array([0, 2, 5, 7, 6, 3, 0])
fig, ax = plt.subplots(figsize=(6, 3))
ax.plot(hour, power_kw, marker="o", color="#16a085")
ax.set(xlabel="Hour of day", ylabel="Power (kW)", title="Synthetic solar profile")
ax.set_ylim(bottom=0)
ax.grid(alpha=0.2)
fig.tight_layout()
plt.show()
print("Peak hour:", hour[power_kw.argmax()])
Keep this in mind

Choose the chart for the question, and label every measurement with units.

LESSON 2 OF 3

Separate a pattern from a cause

25 minEngineering
WHAT YOU WILL DO

Compare mean, median, spread, and correlation on synthetic machine data.

A mean gives an average, a median gives a middle value, and standard deviation describes spread around the mean. For a sample, std(ddof=1) uses the sample standard deviation. These summaries answer different questions, so inspect more than one.

Correlation describes how two numeric variables move together. It does not prove one causes the other. For example, a machine load could raise both temperature and vibration. Check the data collection process before claiming that temperature caused vibration.

See it in action

example.pyPython 3
import numpy as np

# Synthetic machine measurements, not a physical calibration.
temperature = np.array([30, 35, 40, 45, 50, 55], dtype=float)
vibration = np.array([1.1, 1.4, 1.3, 1.8, 2.0, 2.1])
print("Mean vibration:", round(vibration.mean(), 3))
print("Median vibration:", np.median(vibration))
print("Sample spread:", round(vibration.std(ddof=1), 3))
print("Correlation:", round(np.corrcoef(temperature, vibration)[0, 1], 3))
print("A shared cause, such as load, could explain this pattern.")
Keep this in mind

Describe the pattern carefully before trying to explain its cause.

LESSON 3 OF 3

Build an interval with resampling

25 minFinance
WHAT YOU WILL DO

Estimate uncertainty in a synthetic average using a reproducible bootstrap.

One sample mean is only an estimate. A bootstrap repeatedly samples the observed values with replacement, so the same value can appear more than once in a resample. Recalculate the mean each time to see how much the estimate moves.

We use the middle 95% of bootstrap means as a rough interval. This method assumes the sample is reasonably representative and observations are independent. A tiny sample or linked time-series returns can violate those assumptions. The synthetic payment values here are educational, not investment advice.

See it in action

example.pyPython 3
import numpy as np

# Synthetic independent payment-processing fees, in currency units.
fees = np.array([2.0, 2.4, 2.1, 2.8, 2.5, 2.2, 2.7, 2.3])
rng = np.random.default_rng(42)
samples = rng.choice(fees, size=(2000, len(fees)), replace=True)
bootstrap_means = samples.mean(axis=1)
low, high = np.quantile(bootstrap_means, [0.025, 0.975])
print("Observed mean:", round(fees.mean(), 3))
print("Approximate 95% interval:", round(low, 3), round(high, 3))
Keep this in mind

Report uncertainty with the estimate and state the assumptions behind it.

ABOUT THE LEARNING LAB

Free, open and run by a nonprofit.

This page is part of Python to AI, a free course of 20 modules and 60 lessons in the engineering.fit( ) Learning Lab. The Learning Lab is built and run by engineering.fit( ), a nonprofit founded by Abdullateef Opeyemi Bakare that helps African engineering students gain research experience. You do not need an account or pay a fee to learn.

Course outline · Project lab · Visit engineering-fit.org