Analytics & ML · Study deck

Feature Scaling Lab: Statistical Analysis

Task: The code defines a MAD_THRESHOLD constant but does not implement MAD outlier detection.

Data Dora is your guide for this deck.

dataqualitynormalization
Data Dora, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Test step 7: analyze statistics with a concrete scenario and pass criteria.
  • Validate feature scaling leakage controls with a concrete scenario and pass criteria.
  • 'test step 7: analyze statistics with a concrete scenario and pass criteria'
  • validate feature scaling leakage controls with a concrete scenario and pass criteria
iotclass.org

Major section

MAD Filtering Challenge

Task: The code defines a MAD_THRESHOLD constant but does not implement MAD outlier detection.

  • Expected Outcome: MAD should detect outliers even when extreme values skew the mean and standard deviation.
${[0, 0.25, 0.5, 0.75, 1].map(f => { const y = pad.top + f * plotH; const val = (yMax - (yMax - yMin) * f).toFixed(1); return ` ${val}`; }).join("")} Sample index Value Noisy True Smoothed
iotclass.org

Major section

Challenge 3: Cross-Sensor Validation

If it is very bright (high light), temperature should be reasonable for daytime.

  • Expected Outcome: The system should detect when sensor readings are physically inconsistent with each other.
${[0, 0.25, 0.5, 0.75, 1].map(f => { const y = pad.top + f * plotH; const val = (yMax - (yMax - yMin) * f).toFixed(1); return ` ${val}`; }).join("")} Sample index Value Noisy True Smoothed
iotclass.org

Major section

Normalize Sensors for Anomalies

A neural network needs all inputs on the same scale to detect abnormal conditions.

  • The network would learn to minimize CO2 error while ignoring temperature and humidity!
  • Key Insight: Without normalization, the neural network's loss function is dominated by the largest-magnitude features.

Why it matters

Min-max scaling ensures each sensor contributes proportionally to its information content, not its arbitrary measurement scale.

${[0, 0.25, 0.5, 0.75, 1].map(f => { const y = pad.top + f * plotH; const val = (yMax - (yMax - yMin) * f).toFixed(1); return ` ${val}`; }).join("")} Sample index Value Noisy True Smoothed
iotclass.org

Major section

Normalize After Train/Test Split

The Mistake: Calculating normalization parameters (min, max, mean, std) on the entire dataset before splitting into train and test sets.

  • This causes data leakage, where the test set's statistics influence the training process, leading to overly optimistic performance estimates.
  • Scikit-learn's fit_transform() makes it easy to accidentally normalize everything at once.
${[0, 0.25, 0.5, 0.75, 1].map(f => { const y = pad.top + f * plotH; const val = (yMax - (yMax - yMin) * f).toFixed(1); return ` ${val}`; }).join("")} Sample index Value Noisy True Smoothed
iotclass.org

Major section

Renormalize for New Sensors

Adding a new sensor channel to an existing normalised dataset requires recomputing normalisation parameters.

  • Hardcoded normalisation bounds from the initial dataset will not accommodate the new sensor's value range.
${[0, 0.25, 0.5, 0.75, 1].map(f => { const y = pad.top + f * plotH; const val = (yMax - (yMax - yMin) * f).toFixed(1); return ` ${val}`; }).join("")} Sample index Value Noisy True Smoothed
iotclass.org

Major section

Summary

Catching data quality issues at the source costs 1% of fixing them in the cloud, and normalized data enables fair multi-sensor fusion.

  • Critical Design Principle: The complete "validate-clean-transform" pipeline should run at the edge.
${[0, 0.25, 0.5, 0.75, 1].map(f => { const y = pad.top + f * plotH; const val = (yMax - (yMax - yMin) * f).toFixed(1); return ` ${val}`; }).join("")} Sample index Value Noisy True Smoothed
iotclass.org

Major section

Concept Relationships

Data Validation and Outlier Detection: Range checks and outlier detection must occur before normalization to avoid skewing scaling parameters with invalid data.

  • Multi-Sensor Data Fusion: Normalization enables fair comparison when fusing sensors with vastly different measurement ranges (temperature vs light intensity).
  • Edge Data Acquisition: Edge devices normalize locally to reduce transmission bandwidth and prepare data for edge ML inference.

Why it matters

Missing Value Imputation and Noise Filtering: Cleaning must precede normalization; otherwise, gaps and noise corrupt min/max or mean/std calculations.

${[0, 0.25, 0.5, 0.75, 1].map(f => { const y = pad.top + f * plotH; const val = (yMax - (yMax - yMin) * f).toFixed(1); return ` ${val}`; }).join("")} Sample index Value Noisy True Smoothed
iotclass.org

Major section

Concept Relationships (continued)

Modeling and Inferencing: Neural networks require normalized inputs ([0,1] or mean=0, std=1) for stable gradient descent.

  • Anomaly Detection: Z-score normalization makes distance-based anomaly detection work across features with different scales.
  • Key Insight:: Normalization is the final stage of the validate-clean-transform pipeline.
  • Applying it before validation or cleaning causes incorrect scaling parameters (e.g., min-max uses outlier as max value, compressing all valid data into a tiny range).
iotclass.org

Deck summary

Key takeaways

Task: The code defines a MAD_THRESHOLD constant but does not implement MAD outlier detection.

  • If it is very bright (high light), temperature should be reasonable for daytime.
  • A neural network needs all inputs on the same scale to detect abnormal conditions.
  • The Mistake: Calculating normalization parameters (min, max, mean, std) on the entire dataset before splitting into train and test sets.
  • Adding a new sensor channel to an existing normalised dataset requires recomputing normalisation parameters.
iotclass.org

Retrieval practice

Recall check 1 of 3

Data Dora says: answer from memory, then check your reasoning.

Q1Place each normalization-lab responsibility where it lives so you can reproduce a scale transform and reverse it without leaking test information.

ARaw Values and Training Split
BStored Scaling Parameters
CMin-Max or Z-Score Transform
DNormalized Output Checks
Show answer

Answer: A reproduce a scale transform and reverse it without leaking test information.

Q2Complete the sensor data quality pipeline:

Adf = df[df[column].isna() | df[column].between(-40, 85)]
Bdf = df[df[column].between(-40, 85)]
Cdf = df.query(f'{column} > 0')
Ddf = df[df[column] != 0]
Show answer

Answer: A Sensor data cleaning validates physical limits while preserving missing markers, then interpolates the gaps and smooths with an exponential moving average.

iotclass.org

Retrieval practice

Recall check 2 of 3

Data Dora says: answer from memory, then check your reasoning.

Q3You are training a neural network to classify room occupancy using temperature (15-35C) and CO2 (400-5000 ppm) sensor data. Without normalization, what problem will the model likely exhibit?

AThe model will learn the sensor scales through its weights, so retaining the raw ranges should give temperature and CO2 a comparable influence during optimization.
BThe model will ignore temperature entirely because smaller values are deleted before training rather than merely underweighted by gradients
CThe model will disproportionately weight CO2 because its numerical range is ~200x larger, making gradient updates dominated by CO2 features
DThe model will fail to converge no matter how features are scaled, because normalization cannot affect gradient size or learning dynamics
Show answer

Answer: C Without normalization, CO2 values (400-5000) are roughly 200x larger than temperature values (15-35).

iotclass.org

Retrieval practice

Recall check 3 of 3

Data Dora says: answer from memory, then check your reasoning.

Q4A humidity sensor dataset has the values [45, 48, 50, 52, 55, 99, 47, 51, 49, 50] where the value 99 is a stuck-sensor outlier. Which normalization method would be LEAST affected by this outlier?

AMin-Max scaling (range becomes 45-99, compressing most data into a small portion)
BRobust scaling using median and IQR (median=50, IQR based on 25th/75th percentiles)
CZ-score normalization (mean and std are both affected by the outlier)
DNo normalization needed for humidity data
Show answer

Answer: B Robust scaling uses the median (resistant to outliers) and interquartile range (25th to 75th percentile, also resistant).

iotclass.org

Print reference

Answers

Answer key.

  1. A · reproduce a scale transform and reverse it without leaking test information.
  2. A · Sensor data cleaning validates physical limits while preserving missing markers, then interpolates the gaps and smooths with an exponential moving average.
  3. C · Without normalization, CO2 values (400-5000) are roughly 200x larger than temperature values (15-35).
  4. B · Robust scaling uses the median (resistant to outliers) and interquartile range (25th to 75th percentile, also resistant).
iotclass.org