Data Analysis for Engineers/Module 5

Module 5 · Section 1 of 12

Module Overview

The running regression dataset is a facility energy vs temperature & activity model (relevant to power, process, and facilities work), and the earlier lessons use manufacturing / reliability examples. Discipline-leaning examples are tagged inline.

Learning Outcomes

  • Apply hypothesis testing and regression analysis to engineering data
  • Understand and build basic predictive models
  • Evaluate model performance correctly and avoid common pitfalls
  • Know when ML is (and isn't) the right tool for an engineering problem

Run cells top to bottom. The first cell sets up shared imports and a synthetic monthly energy dataset (with temperature and an activity-index feature) used across the regression lessons.


%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy import stats

plt.rcParams["figure.dpi"] = 100
np.random.seed(42)                 # fixed seed -> everyone gets identical data

# --- Synthesise 60 months of facility energy demand with two known drivers ---
# We BUILD the target from avg_temp_c and activity_index so later lessons can
# check whether the fitted coefficients recover the ones used here.
n_months = 60
months_idx = pd.date_range("2019-01-01", periods=n_months, freq="MS")   # month-start dates

# seasonal temperature: a sine wave over the year plus small noise
avg_temp_c = 27 + 3 * np.sin((months_idx.dayofyear - 105) / 365 * 2 * np.pi) + np.random.normal(0, 0.6, n_months)
# activity index: a slow linear upward trend plus noise
activity_index = 100 + np.arange(n_months) * 0.35 + np.random.normal(0, 1.5, n_months)

demand_mw = (
    1500
    + 45 * (avg_temp_c - 27)          # +45 MW per degree C above 27
    + 6.0 * (activity_index - 100)    # +6 MW per activity-index point above 100
    + np.random.normal(0, 25, n_months)   # unexplained noise
)

demand_df = pd.DataFrame({
    "date": months_idx,
    "avg_temp_c": np.round(avg_temp_c, 2),
    "activity_index": np.round(activity_index, 2),
    "demand_mw": np.round(demand_mw, 1),
})
print(demand_df.shape)
demand_df.head()

44 / 63 sections · Course home · Join the coaching cohort