Fit ordinary least squares on two training devices; predict a reference temperature on the third.
The focus of this experiment is to fit and interpret a linear sensor-calibration relationship. Students then calculate residuals and held-out error under stated units, and compare calibration and validation evidence without extrapolating beyond the data. The Concepts view explains the operation before the practical work; the Simulation view is used to examine reference and changed inputs, not to substitute for actual measurements.
Learning objectives
Fit and interpret a linear sensor-calibration relationship.
Calculate residuals and held-out error under stated units.
Compare calibration and validation evidence without extrapolating beyond the data.
Identify the configured inputs (Held-out sensor bias (°C)) and record the corresponding observed outputs with units where applicable.
Compare the reference calculation or decision with an independent implementation or authorized observation; state any discrepancy and the applicable model boundary.
Expected learning outcomes
On completion, students can fit and interpret a linear sensor-calibration relationship, calculate residuals and held-out error under stated units, and compare calibration and validation evidence without extrapolating beyond the data.
Required deliverables
Submit the derivation or state trace for the named operation, the exact reference and changed configurations, the associated simulator or practical evidence, and a short validation statement addressing compare calibration and validation evidence without extrapolating beyond the data. Separate predicted values from observations.
Prerequisite knowledge and related learning
Review the following catalogue prerequisites before starting. After completion, continue to Fault classification & decision thresholds.
The supplied model, datasets and local Python or Colab notebook. Report the data partition and execution environment; do not claim physical edge-device performance from host measurements.
Begin with a manual prediction, record the baseline, change one independent condition at a time, and compare the resulting trace or measurements with the original prediction. Record observations and uncertainty separately from reference values. Follow the experiment’s specific procedure, safety limits, and acceptance checks.
M02 · learning outcome
Understand the experiment
Scientific architecture · Regression for sensor calibration
Scientific concept map: Raw sensor values — Calibration observations; Training pairs — Reference targets; Linear fit — Slope and intercept; Prediction — Calibrated measurement; Residuals — MAE / RMSE.
Scientific foundations and analytical reasoning
Ordinary least squares fits slope covariance/variance and intercept mean(y)−slope*mean(x). Held-out errors measure generalization.
Before operating the equipment or executing the program, derive the expected outcome using the required theoretical work in Experiment. Use the diagram to identify the variables and system boundaries.
Scientific theory · Least-squares regression
For y=wx+b, ordinary least squares minimizes the sum of squared residuals. With nonconstant x, w=Σ(x−x̄)(y−ȳ)/Σ(x−x̄)^2 and b=ȳ−wx̄. Evaluate frozen coefficients on held-out records. MAE measures average absolute error; RMSE penalizes large errors more strongly.
Worked example and engineering interpretation
For points (1,3),(2,5),(3,7), w=2 and b=1. Prediction at x=4 is 9. If the observed value is 10, the signed residual y−ŷ is 1. A shifted sensor input can change prediction without changing the fitted coefficients.
Engineering principles · additional worked teaching example
A linear calibration y=ax+b represents gain and offset. Points (0,2),(10,12) imply slope1 and offset2; x=6 predicts8. Residual is measured target minus predicted value, and test bias can differ from train residuals.
From theory to experiment
Predict the reference result before operating the workbench; check the actual intermediate state, units and constraints. The existing simulation, implementation and procedure below are distinct sources of evidence.
How to investigate Regression for sensor calibration
Fit ordinary least squares on two training devices; predict a reference temperature on the third.
Analytical investigation means collecting an observation, identifying the mechanism, using a calculation or state trace to explain it, and checking your conclusion against evidence. Controlled comparison means changing one independent variable, holding the remaining relevant conditions constant, and measuring a dependent variable against a baseline. Experimental validation means comparing a predicted result to a reproducible observation or assertion; agreement inside a model does not certify hardware. Evidence-based reasoning connects a specific observation to a theoretical rule and states uncertainty, not merely an opinion. Performance characterization records a named metric and its units across conditions; sensitivity analysis changes one parameter across several values. A threat assessment links an asset, threat, consequence and evidence to a mitigation.
Experiment-specific guided practice
Objective: Fit ordinary least squares on two training devices; predict a reference temperature on the third.
Set Held-out sensor bias (°C) = 0. Observe the calculated results and trace.
Change Held-out sensor bias (°C) = 5. Zero bias should beat the mean baseline; added bias increases MAE.
Restore the reference values. Compare MAE, RMSE and fixed slope. Explain why test bias does not refit the model.
Reference check:
Model boundary:
Independent task and submission evidence
2. Change Held-out sensor bias (°C) = 5. Zero bias should beat the mean baseline; added bias increases MAE. Record the named input, prediction, actual output and one limitation; restore the original condition and repeat.
Before execution write the independent variable and its levels, dependent observation with units where applicable, baseline, controlled variables, measurement method and expected result. For a state machine use state/event/output rather than inventing a numeric metric. Record failures and repeat the baseline. A weak conclusion is “it works”; a supported conclusion names the changed setting, observed value/state, corresponding rule and one limitation.
Trial
Changed setting
Fixed settings
Predicted result
Actual observation / units
Evidence / uncertainty
A: baseline
Reference
Record
Predict
Record
Record
B: one change
Record
Same as A
Predict
Record
Record
A: repeat
Restore
Same as A
Predict
Record
Record
Completion: submit the filled table, relevant simulator screenshot or terminal/notebook output, reasoning with units/assumptions, and one limitation. Preserve the independent assessment questions; this guide does not fill their answers.
Fit ordinary least squares on two training devices; predict a reference temperature on the third.
Method: OLS y = w x + b; compare a training-mean predictor.
Data provenance: deterministic generated teaching fixture or configured analytical model. No real sensor data, physical inference performance, or production deployment is claimed.
Worked engineering reasoning and boundary conditions
Engineering reference configuration: Held-out sensor bias (°C) = 0. In the classroom model, MAE = 1.34839; RMSE = 1.549308; Mean baseline MAE = 12.02775; Slope = 2.071396. The model is fitted only on training rows; test sensor bias changes predictions, not the fitted coefficients. OLS y = w x + b; compare a training-mean predictor
Use the diagram to follow the calculation or state progression. Keep the teaching configuration separate from the independent exercise values; compare observations with the actual model and implementation.
Mathematical representation and interpretation
Linear regression calibration
x is the sensor input, y is the calibration reference, beta_0 and beta_1 the fitted intercept and slope. Estimate on training devices; evaluate on held-out devices.
Explore the teaching example independently of the simulator. Each step reveals an operation, data relationship or calculated state. The Simulation view has separate editable inputs.
Step 1 of 7 · Observation 80
Observation 80
Reference
60.21
Prediction
57.858627
Observation 86
Reference
49.98
Prediction
48.951626
Observation 93
Reference
57.69
Prediction
55.372952
Observation 100
Reference
60.2
Prediction
61.794278
Observation 106
Reference
55.17
Prediction
52.887277
Observation 112
Reference
46.83
Prediction
45.844532
Observation 119
Reference
54.54
Prediction
52.265859
Teaching example only; inspect live calculations or real practical evidence separately.
Recall the concept before revealing its explanation.
0 / 3 revealed
M02 · 01 / 08How are sensor calibration training and test devices separated?Reveal explanation
Engineering explanation
Fit ordinary least squares on two training devices; predict a reference temperature on the third.
M02 · 02 / 08Which regression method and baseline are compared?Reveal explanation
Engineering explanation
OLS y = w x + b; compare a training-mean predictor
M02 · 03 / 08What happens to MAE when held-out sensor bias increases?Reveal explanation
Engineering explanation
Zero bias should beat the mean baseline; added bias increases MAE.
M02 · 04 / 08What is the difference between MAE and RMSE?Reveal explanation
Engineering reasoning
MAE averages absolute errors; RMSE takes the square root of mean squared errors, weighting larger errors more heavily.
M02 · 05 / 08Why must the OLS slope stay fixed when test bias changes?Reveal explanation
Engineering reasoning
The fit uses training data only; changing held-out inputs affects predictions, not training coefficients.
M02 · 06 / 08A regression calibrates a sensor. Select every technically valid statement.
A. Fit coefficients on the training devices.
B. Evaluate prediction error on a held-out device.
C. Use the held-out labels to tune coefficients without reporting it.
D. Training error proves performance on unseen devices.Reveal explanation
Applied scenario
Correct: A. Fit coefficients on the training devices.; B. Evaluate prediction error on a held-out device.
M02 · 07 / 08In Regression for sensor calibration, which reference and changed settings are prescribed for Held-out sensor bias (°C)?Reveal explanation
Controlled configuration
Held-out sensor bias (°C): 0 → 5; hold the remaining settings fixed.
M02 · 08 / 08What expected result distinguishes the reference and changed trials in Regression for sensor calibration?Reveal explanation
Expected observation
Zero bias should beat the mean baseline; added bias increases MAE.
Loading live engineering instrument…Supplementary research apparatusLoading experiment-specific apparatus…Scientific model · primary investigation
Simulation task
Fit ordinary least squares on two training devices; predict a reference temperature on the third.
Explore the model using its own controls. Record a prediction before changing a condition. Compare the reference with a changed condition, then use the Experiment tab for the procedure, acceptance criteria and notebook. Model outputs and physical observations must remain separate.
Interactive engineering workbenchM02 · Scientific model
Readout from the original computational model; not physical measurements.
Loading instrument…
Awaiting model display.
Experimental instrumentation · A/B
Compare two model conditions
Capture a baseline, change one experimental condition, run the model if required and capture the comparison. Snapshots contain visible controls and display text, not physical sensor readings. Review before exporting.
Ask Dr. Mohammad locally, or prepare an experiment-aware prompt for ChatGPT, Gemini or Claude. The external providers open in their own tabs; nothing is automatically submitted.
Public course objective, displayed commands, source excerpts and procedure. Private assessment content is not collected.
Prepare a contextual AI prompt
0 characters
Common secret and email patterns are redacted on preparation; this is not a comprehensive privacy filter. Review the entire editable prompt, including student work and unpublished research, before sharing. The providers apply their own accounts, privacy settings and limits.
Prepare → review → copy & open your selected provider → paste and submit there.
Independent theoretical exercises
Before the simulation or practical, solve both experiment-specific tasks. List the given inputs, show the intermediate calculation or state trace, identify the expected observation, and state a limitation. Show formulas and intermediate calculations where relevant, or draw the requested state/sequence diagram. These are independent classroom fixtures; where they differ from the reference configuration below, do not treat them as measured values. Compare your predictions with the corresponding experiment afterwards.
01 · Predict and derive using the given inputs
For pairs (20,21),(25,26),(30,31), calculate slope/intercept and prediction at x=27.
Engineering method — A linear calibration y=ax+b represents gain and offset. Points (0,2),(10,12) imply slope1 and offset2; x=6 predicts8. Residual is measured target minus predicted value, and test bias can differ from train residuals. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
02 · Compare or justify using evidence
For true value 29 at x=27, compute error and absolute error. Explain why fitting to held-out device hides calibration bias.
Engineering method — A linear calibration y=ax+b represents gain and offset. Points (0,2),(10,12) imply slope1 and offset2; x=6 predicts8. Residual is measured target minus predicted value, and test bias can differ from train residuals. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
03 · Calculation
Calculation · Independent work
Given pairs (10,13),(20,25) on a perfect line, derive a,b and predict at x=15. If true target is20, compute residual.
Calculation — A linear calibration y=ax+b represents gain and offset. Points (0,2),(10,12) imply slope1 and offset2; x=6 predicts8. Residual is measured target minus predicted value, and test bias can differ from train residuals. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
Work is saved locally when browser storage is available. Export it for submission; no remote upload or automatic grade is assigned.
Expanded independent theoretical exercise bank
Progress from calculation and interpretation to diagnosis and controlled engineering design. Complete the questions without opening the simulation first; show intermediate steps.
Intermediate · Explain a changed-input result
Independent theoretical exercise · M02-01
Use the reference configuration (Held-out sensor bias (°C) = 0), but change Held-out sensor bias (°C) = 0.2. The model reports MAE = 1.345215. Explain the governing rule and assumptions that make this output plausible; identify an independent verification method.
Intermediate · Quantitative comparison
Independent theoretical exercise · M02-02
Two model observations of MAE are 1.34839 (reference) and 1.345215 (changed condition). Compute signed change and, when the reference is nonzero, percentage change. Explain why units matter.
Intermediate · Interpret a technical trace
Independent theoretical exercise · M02-03
For Held-out sensor bias (°C) = 5, the model supplies this excerpt from Calculated trace:
Item · Value · Explanation
Intercept · 3.795203 ·
Test rows · 40 ·
Sensor bias · 5 ·
Compute the range (maximum minus minimum) of the Value column in these rows. Identify the maximum observation. Do not extrapolate beyond these rows.
Advanced · Reverse reasoning
Independent theoretical exercise · M02-04
An observation is MAE = 10.259719. Candidate A uses Held-out sensor bias (°C) = 0. Candidate B changes the listed settings (Held-out sensor bias (°C) = 5) and keeps the remaining settings fixed. Which is consistent with the observation? If both can explain it, say what additional evidence is required.
Advanced · Diagnose a reported mismatch
Independent theoretical exercise · M02-05
A student configures Held-out sensor bias (°C) = 5 while preserving all other reference settings, but copies the reference report of MAE = 1.34839. Evaluate whether the report is justified. Identify the first configuration/output check to perform.
Challenging · Design a controlled verification
Independent theoretical exercise · M02-06
Design a controlled comparison for Regression for sensor calibration using reference Held-out sensor bias (°C) = 0 and test Held-out sensor bias (°C) = 0.2. Specify the changed setting(s), measured metric MAE, controls, repetitions, an acceptance check and what evidence can distinguish an actual implementation from the model.
Step-by-step experimental procedure
Fit ordinary least squares on two training devices; predict a reference temperature on the third.
1 · Reference workbench configuration
Use the named reference workbench and its reference inputs. Additional live instruments may have different controls; use the matching instrument. Record virtual and practical results separately.
Held-out sensor bias (°C)0
2 · Perform the investigation in order
Set Held-out sensor bias (°C) = 0. Observe the calculated results and trace.
Change Held-out sensor bias (°C) = 5. Zero bias should beat the mean baseline; added bias increases MAE.
Restore the reference values. Compare MAE, RMSE and fixed slope. Explain why test bias does not refit the model.
3 · Compare controlled trials
Trial
Independent change
Expected check
Observation
Reference
Use reference inputs above
Zero bias should beat the mean baseline; added bias increases MAE.
Record actual result
Controlled change
Held-out sensor bias (°C) = 5
Zero bias should beat the mean baseline; added bias increases MAE.
Record actual result
4 · Analyze and report
Compare MAE, RMSE and fixed slope. Explain why test bias does not refit the model.
Required evidence: Record the regression for sensor calibration comparison and justify the changed outcome from the calculated trace.
Model boundary: OLS y = w x + b; compare a training-mean predictor
Controlled investigation · reproducible evidence
Method. Use the existing reference workbench configuration and the named controlled changes below. A controlled variable stays fixed while the independent variable is intentionally changed; the dependent variable is the resulting observed output. First predict each trial from the Concepts page. Run the baseline, then change only the specified setting and record the outcome. For deterministic traces one execution per case and a repeated verification are sufficient; for timing or stochastic measurements repeat at least five times, recording each run, median and range. Reset to the reference state between independent comparisons.
Trial
Independent change
Dependent observation
Reference
Use reference inputs above
Record actual outcome and units
Controlled change
Held-out sensor bias (°C) = 5
Record actual outcome and units
Evidence: attach the completed comparison table, one trace or screenshot per condition, and actual practical terminal/hardware evidence where applicable. Explain any prediction mismatch and distinguish modeled behavior from measured results.
Loading laboratory-specific procedure…
Python / Google Colab notebook
Original Python reference, generated teaching fixture. Validated locally in a fresh Jupyter kernel. Download, then upload to Google Colab.
Record the training slope and intercept; start with zero held-out sensor bias. Advance 40 samples.
Reset, choose +5 °C bias, and repeat 40 samples without refitting. Compare MAE, RMSE and residuals against the first run.
Compare actual versus predicted points and explain why test-device bias changes errors but not the regression coefficients.
Export evidence and independently verify against the supplied Python regression model.
Evidence: retain your prediction, configuration, observations and exported event history; distinguish calculated teaching-model results from physical measurements.
Complete practical procedure & acceptance
Read the method, enter a prediction and save the reference baseline.
Apply the controlled change and compare metrics and plot. Compare MAE, RMSE and fixed slope. Explain why test bias does not refit the model.
Restore the reference and verify that the original metrics return. Enter an invalid parameter and confirm that export is disabled, then restore.
Run the independent local Python computation from the extracted portal root:
BASH · Command
python3 verification/ml168_practical.py all
Expected: ten passing checks and a result object for each lab. This uses Python standard library only. Compare the default result for M02 to the browser output.
Export actual observations and explain one limitation.
Student submission: include your prediction, exported baseline and controlled result, actual terminal output, and a short interpretation. Do not submit the build validation report as your own evidence.
Experimental notebook
Record your own results. Values are not prefilled or independently verified.
Record & discuss
Portfolio exports use related core lab P32 for compatibility. The supplementary experiment ID is preserved in the attachment. Local completion is self-reported.
Download this notebook and open Google Colab. Select File → Upload notebook and choose the downloaded .ipynb.
Read the Markdown instructions before each executable cell. Use a Python runtime, run cells from top to bottom, and resolve imports if necessary.
Perform the baseline and controlled changes. Save the notebook with actual outputs and your written interpretation.
Execution scope: Default computational cells passed isolated local Python execution; physical equipment and live services require separate verification.
01Instructions · Markdown
# m02 · Regression for sensor calibration
**PSUT IoT Engineering Studio — Dr. Mohammad Alja’afreh**
## Introduction
Fit ordinary least squares on two training devices; predict a reference temperature on the third.
## How to run
1. Download this notebook from the laboratory page. Open Google Colab → File → Upload notebook.
2. Select a Python CPU runtime. Run cells from top to bottom using Shift+Enter, or Runtime → Run all.
3. Read the printed observations and assertions. Change one parameter at a time and rerun the relevant cell.
4. Save your own outputs and compare them to the portal Experiment tab.
**Execution boundary:** Original Python reference, generated teaching fixture. Do not run the hardware or service commands in Colab. No real credentials are needed. The notebook is self-contained.
02Instructions · Markdown
## Experiment-specific preparation
Fit ordinary least squares on two training devices; predict a reference temperature on the third.
**Reference procedure (use the matching simulator/WSL tool where named, not an unrelated service):**
1. Set Held-out sensor bias (°C) = 0. Observe the calculated results and trace.
2. Change Held-out sensor bias (°C) = 5. Zero bias should beat the mean baseline; added bias increases MAE.
3. Restore the reference values. Compare MAE, RMSE and fixed slope. Explain why test bias does not refit the model.
**Evidence:**
**Boundary:**
03Instructions · Markdown
## 1. Objectives and reference condition
- Reproduce the specific computational mechanism in this laboratory.
- Inspect the output, compare the reference condition with a changed or rejected condition where implemented, and explain any discrepancy.
- Distinguish actual local Python execution from mock, physical and external-service observations.
## 2. Environment check
04Python · executable cell
PYTHON · Code cell
# =====================================================================
# M02 | Code cell 01 | Regression for sensor calibration
# Purpose: 1. Objectives and reference condition - Reproduce the specific computational mechanism in this laboratory. - Inspect the output, compare the reference condition with a changed or rejected condition where implem
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
import sys
print("Python",sys.version.split()[0])
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert sys.version_info >= (3,10)
## 3. Implementation
Read the comments and variable definitions before execution. Assertions must pass; inspect values, not just completion.
06Python · executable cell
PYTHON · Code cell
# =====================================================================
# M02 | Code cell 02 | Regression for sensor calibration
# Purpose: implement only the mechanism named in this laboratory.
# Inputs: the explicit fictional fixture and reference parameters below.
# Output: printed observations and assertions for the controlled trial.
# =====================================================================
import statistics as st,math
def fixture():
rows=[]
for i in range(120):
x=18+(i*7%23)+((i*13%9)-4)/10; v=1+(i*11%17)/5
rows.append(dict(id=i,device=f'node-{1+i//40}',x=x,v=v,y=2.1*x+3+((i*19%13)-6)*.4,fault=int(x+3*v+((i*17%11)-5)/2>36)))
return rows
# Least squares slope and intercept learned on training data only.
rows=fixture();train,test=rows[:80],rows[80:]
mx=st.mean(r['x'] for r in train);my=st.mean(r['y'] for r in train)
w=sum((r['x']-mx)*(r['y']-my) for r in train)/sum((r['x']-mx)**2 for r in train)
b=my-w*mx
### Step 2 · Run the reference calculation
Read the comments and variable definitions before execution. Assertions must pass; inspect values, not just completion.
08Python · executable cell
PYTHON · Code cell
# =====================================================================
# M02 | Code cell 03 | Regression for sensor calibration
# Purpose: implement only the mechanism named in this laboratory.
# Inputs: the explicit fictional fixture and reference parameters below.
# Output: printed observations and assertions for the controlled trial.
# =====================================================================
err=[w*r['x']+b-r['y'] for r in test]
mae=st.mean(map(abs,err));rmse=math.sqrt(st.mean(e*e for e in err));baseline=st.mean(abs(r['y']-my) for r in test)
print('slope',w,'intercept',b,'MAE',mae,'RMSE',rmse,'mean baseline MAE',baseline)
assert mae<baseline
## Original portal implementation (reference only)
These are the actual laboratory snippets. They are retained for comparison; follow the portal setup for WSL, hardware or services. They are **not** executed by Run all.
```bash
python3 verification/ml168_practical.py all
```
10Instructions · Markdown
## 4. Results and analysis
Record the actual output and whether the assertions pass. Identify a parameter to vary, state your prediction, repeat the reference calculation, then explain the changed result.
| Trial | Configuration | Observation | Interpretation |
|---|---|---|---|
| A | Reference | | |
| B | One controlled change | | |
| C | Reference repeat | | |
**Limitations:** Original Python reference, generated teaching fixture. Notebook success does not certify external equipment or services.
11Instructions · Markdown
## Guided reasoning and evidence
A controlled comparison changes one independent input while keeping the other relevant inputs fixed; the dependent variable is the recorded output. Use this lab’s reference condition above.
**Independent task:** 2. Change Held-out sensor bias (°C) = 5. Zero bias should beat the mean baseline; added bias increases MAE. Record the named input, prediction, actual output and one limitation; restore the original condition and repeat.
| Trial | Input/configuration | Prediction | Observation | Evidence / limitation |
|---|---|---|---|---|
| A | Reference | | | |
| B | Changed input | | | |
| A repeat | Reference | | | |
A conclusion is supported only when it cites the recorded values or observed states and explains them with the experiment theory.
Shared research workbenches · network designer & advanced studiesConcurrent-device simulation & Monte Carlo research