A gas-turbine operator cannot choose tomorrow’s weather, but they can observe a weather forecast before deciding how to schedule the plant. This notebook asks a deliberately simple question:
How is the NOx concentration observed at the plant associated with ambient temperature?
The goal is to build and diagnose a first regression model. It is not a complete physical model of the turbine, and it does not tell us what would happen if we intervened to change ambient temperature.
Learning objectives
Define a response, predictor, and residual.
Explain why ordinary least squares minimizes mean squared error.
Fit and interpret a one-variable least-squares line.
Use residuals and \(R^2\) to assess in-sample fit.
Distinguish association from causation.
1. Load the course dataset
The Foundations notebooks introduced this hourly gas-turbine dataset. We repeat the setup here so the notebook runs independently in Colab. Each row is an hourly aggregate of plant measurements.
import numpy as npimport pandas as pdimport matplotlib.pyplot as pltimport statsmodels.api as smfrom pathlib import Pathfrom urllib.request import urlretrieveplt.style.use("seaborn-v0_8-whitegrid")DATA_URL ="https://raw.githubusercontent.com/changyaochen/MECE4520/master/site/data/gas-turbine-course.csv"data_path =next((path for path in [Path("../data/gas-turbine-course.csv"), Path("site/data/gas-turbine-course.csv"), Path("gas-turbine-course.csv")] if path.exists()), Path("gas-turbine-course.csv"))ifnot data_path.exists(): urlretrieve(DATA_URL, data_path)data = pd.read_csv(data_path)data.head()
campaign_year
AT
AP
AH
AFDP
GTEP
TIT
TAT
TEY
CDP
CO
NOX
0
2011
4.5878
1018.7
83.675
3.5758
23.979
1086.2
549.83
134.67
11.898
0.32663
81.952
1
2011
4.2932
1018.3
84.235
3.5709
23.951
1086.1
550.05
134.67
11.892
0.44784
82.377
2
2011
3.9045
1018.4
84.858
3.5828
23.990
1086.5
550.19
135.10
12.042
0.45144
83.776
3
2011
3.7436
1018.3
85.434
3.5808
23.911
1086.5
550.17
135.03
11.990
0.23107
82.505
4
2011
3.7516
1017.8
85.182
3.5781
23.917
1085.9
550.00
134.67
11.910
0.26747
82.028
2. Understand the measurements
Before focusing on one relationship, orient yourself to the full system.
Column
Meaning
campaign_year
Data-collection campaign year (2011–2015)
AT
Ambient temperature (°C)
AP
Ambient pressure (mbar)
AH
Ambient humidity (%)
AFDP
Air-filter differential pressure (mbar)
GTEP
Gas-turbine exhaust pressure (mbar)
TIT
Turbine inlet temperature (°C)
TAT
Turbine-after temperature (°C)
TEY
Turbine energy yield (MWh)
CDP
Compressor discharge pressure (mbar)
CO
Carbon monoxide concentration (mg/m³)
NOX
Nitrogen oxides concentration, NO + NO₂ (mg/m³)
3. Focus on ambient temperature and NOx
For this first model, use AT, ambient temperature in °C, as the predictor and NOX, NOx concentration in mg/m³, as the response.
Here, \(\varepsilon_i = y_i - \hat{y}_i\) is the residual: the vertical difference between an observation and its prediction.
6. Choose a loss function
A raw mean residual can cancel positive and negative errors. Mean absolute error (MAE) avoids cancellation, but its absolute-value kink makes optimization less convenient. Ordinary least squares uses mean squared error (MSE):
The fitted slope is the predicted difference in NOx concentration associated with a one-degree-Celsius difference in ambient temperature. This is an association, not an intervention claim.
8. Inspect the residuals
Residuals reveal the variation that the line leaves unexplained. Start with their distribution: what size error is typical, and are there unusually large errors? A residual histogram can assess whether a Normal approximation is plausible, but it cannot prove a Normal-error assumption.
A residual mean near zero is guaranteed by OLS when the model includes an intercept. More revealing questions are whether the center stays near zero and whether the spread stays about the same width across the range of AT values.
The red line summarizes the average residual at nearby temperature values. A pattern above and below zero suggests that a straight line misses systematic structure. A changing vertical spread suggests heteroscedasticity. These diagnostics identify useful next modeling steps, such as nonlinear features, additional predictors, or time-aware validation.
9. Summarize fit with \(R^2\)
A mean-only baseline predicts every observation with \(\bar{y}\). Its total squared error is the total sum of squares (TSS). The regression’s squared error is the residual sum of squares (RSS):
Thus, \(R^2\) is the fraction of baseline squared error that the fitted line removes. It describes in-sample fit, not causality or future predictive accuracy.
Why can the raw mean residual be misleading as a loss function?
What would a residual-versus-AT plot look like if a straight-line conditional mean were adequate?
If \(R^2 \approx 0.31\), what does that say about the regression line relative to the mean-only baseline?
Keep your answers in your own notes. Later regression materials will introduce confidence intervals, hypothesis tests, additional predictors, and out-of-sample validation.