Analytics & ML · Study deck

Imputation and Noise Filtering

Picture a cold-room chart with six missing minutes just before an alarm.

Data Dora is your guide for this deck.

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

After studying this chapter

Learning objectives

You will be able to:

  • Implement Missing Data Handling: Apply appropriate imputation strategies (forward-fill, interpolation, seasonal decomposition) for different sensor types
  • Compare Imputation Methods: Evaluate trade-offs between forward-fill, interpolation, and seasonal decomposition based on data characteristics
  • Design Noise Filters: Implement moving average, median, and exponential smoothing filters and assess their signal conditioning performance
  • Distinguish Strategy by Sensor Type: Justify the correct imputation and filtering approach based on sensor semantics and physical behavior
iotclass.org

Major section

Start With the Story

The analyst can carry the last value forward, draw a line across the gap, or leave it empty.

  • Each choice changes what a later manager may believe about the food and the fault.
  • A smooth line is not proof that the missing event never happened.
  • This opening does not choose one repair for every signal.

Key terms

If any answer
If any answer is no, do not use the fixed series for a live choice.
Forward Fill: gap=${fwd_gapLen} samples, max_gap=${fwd_maxGap} ${gapShade} ${[yMin, (yMin + yMax) / 2, yMax].map(v => `${v.toFixed(1)}`).join("")} ${origDots} ${imputedDots} Sample Index Original data Forward-filled Gap too large (rejected)
iotclass.org

Major section

Start With the Story (continued)

A later repair may support review or study, but it must not silently rewrite the record used for a safety action.

  • Practitioner matches the rule to the meaning and the decision.
  • Under the Hood examines noise shape, window choice, bias, model checks, and how each change affects later work.
  • If any answer is no, do not use the fixed series for a live choice.
iotclass.org

Major section

In 60 Seconds

Missing and noisy sensor readings corrupt every downstream analysis, making data imputation (filling gaps) and filtering (smoothing noise) essential preprocessing steps before any IoT analytics pipeline can produce reliable results.

  • The choice of imputation strategy — forward-fill, interpolation, or model-based — fundamentally affects anomaly detection sensitivity and ML model accuracy.
  • Filling gaps cannot restore information acquisition never captured.

Numbers to remember

0–100%a 12-bit ADC over 0–100% humidity has a 0.0244% step
0.0244%a 12-bit ADC over 0–100% humidity has a 0.0244% step
Forward Fill: gap=${fwd_gapLen} samples, max_gap=${fwd_maxGap} ${gapShade} ${[yMin, (yMin + yMax) / 2, yMax].map(v => `${v.toFixed(1)}`).join("")} ${origDots} ${imputedDots} Sample Index Original data Forward-filled Gap too large (rejected)
iotclass.org

Major section

Why Imputation and Filtering Matter

Missing data and noise are inevitable in real IoT deployments.: Sensors lose power, networks drop packets, and electronic noise corrupts readings.

  • Rather than discard incomplete data, we can intelligently fill gaps and smooth noise.
  • Key question this chapter answers: "How do I fill gaps in sensor data and smooth out noise without losing important information?".

Key terms

Missing data and noise
Missing data and noise are inevitable in real IoT deployments. Sensors lose power, networks drop packets, and electronic noise corrupts readings.
Forward Fill: gap=${fwd_gapLen} samples, max_gap=${fwd_maxGap} ${gapShade} ${[yMin, (yMin + yMax) / 2, yMax].map(v => `${v.toFixed(1)}`).join("")} ${origDots} ${imputedDots} Sample Index Original data Forward-filled Gap too large (rejected)
iotclass.org

Major section

Imputation and Filtering Basics

Core Concept: Missing value imputation fills data gaps using neighboring or historical values, while noise filtering smooths random fluctuations to reveal the underlying signal - both must be matched to sensor semantics.

  • Gaps cause errors or require discarding entire time windows.
  • Proper handling preserves data integrity while enabling downstream processing.
Forward Fill: gap=${fwd_gapLen} samples, max_gap=${fwd_maxGap} ${gapShade} ${[yMin, (yMin + yMax) / 2, yMax].map(v => `${v.toFixed(1)}`).join("")} ${origDots} ${imputedDots} Sample Index Original data Forward-filled Gap too large (rejected)
iotclass.org

Major section

Missing Value Imputation

The first half of the chapter is about deciding what a gap means.

  • A missing temperature reading, a missing motion event, and a missing daily cycle do not deserve the same treatment.
Forward Fill: gap=${fwd_gapLen} samples, max_gap=${fwd_maxGap} ${gapShade} ${[yMin, (yMin + yMax) / 2, yMax].map(v => `${v.toFixed(1)}`).join("")} ${origDots} ${imputedDots} Sample Index Original data Forward-filled Gap too large (rejected)
iotclass.org

Major section

Key Concepts

Missing data imputation: The process of estimating and filling in missing sensor readings using statistical or model-based methods rather than discarding incomplete records.

  • Missingness mechanism: The reason data is missing — Missing Completely at Random (MCAR), Missing at Random (MAR), or Missing Not at Random (MNAR) — which determines which imputation methods are statistically valid.
Forward Fill: gap=${fwd_gapLen} samples, max_gap=${fwd_maxGap} ${gapShade} ${[yMin, (yMin + yMax) / 2, yMax].map(v => `${v.toFixed(1)}`).join("")} ${origDots} ${imputedDots} Sample Index Original data Forward-filled Gap too large (rejected)
iotclass.org

Major section

Median Filter

The median filter is the next tool because it can ignore a spike when most nearby readings are sane.

  • Moving averages reduce random variation, but a single bad spike still enters the average.
Forward Fill: gap=${fwd_gapLen} samples, max_gap=${fwd_maxGap} ${gapShade} ${[yMin, (yMin + yMax) / 2, yMax].map(v => `${v.toFixed(1)}`).join("")} ${origDots} ${imputedDots} Sample Index Original data Forward-filled Gap too large (rejected)
iotclass.org

Major section

Putting Numbers to It

Where $N$ is the window size.

  • Trade-off:: Larger window → better noise rejection BUT longer delay detecting real changes.
  • If monitoring hourly HVAC cycles (3600s), 5-10 sample window (2-4.5s latency) is acceptable.
  • If detecting rapid door opening events (10s timescale), use $N=3$ (1.0s latency max).
Forward Fill: gap=${fwd_gapLen} samples, max_gap=${fwd_maxGap} ${gapShade} ${[yMin, (yMin + yMax) / 2, yMax].map(v => `${v.toFixed(1)}`).join("")} ${origDots} ${imputedDots} Sample Index Original data Forward-filled Gap too large (rejected)
iotclass.org

Major section

Temperature Filter Windows

Scenario: You have a temperature sensor monitoring a cold storage facility.

  • The sensor reports every 10 seconds.
  • You've observed occasional spikes due to electrical interference when the cooling compressor starts (5-10C jumps), and you need to filter these without losing legitimate temperature trends.
  • For cold storage monitoring (not time-critical), 20 seconds is acceptable.

Why it matters

The window should be large enough to ensure spikes are minority values (< 50%) within the window.

Forward Fill: gap=${fwd_gapLen} samples, max_gap=${fwd_maxGap} ${gapShade} ${[yMin, (yMin + yMax) / 2, yMax].map(v => `${v.toFixed(1)}`).join("")} ${origDots} ${imputedDots} Sample Index Original data Forward-filled Gap too large (rejected)
iotclass.org

Major section

Choose Imputation Strategy

When sensor data goes missing, selecting the correct imputation strategy depends on sensor characteristics and downstream requirements.

  • YES → Forward-fill acceptable for gaps < 10x sampling interval.
  • YES → Use seasonal decomposition fill.
  • YES → Use spatial interpolation from neighbors.
  • NO → Use linear interpolation or mark as missing.
Forward Fill: gap=${fwd_gapLen} samples, max_gap=${fwd_maxGap} ${gapShade} ${[yMin, (yMin + yMax) / 2, yMax].map(v => `${v.toFixed(1)}`).join("")} ${origDots} ${imputedDots} Sample Index Original data Forward-filled Gap too large (rejected)
iotclass.org

Major section

Detect Outliers Before Imputing

The Mistake: Running imputation before outlier detection, causing outliers to be forward-filled or interpolated into the data stream, permanently corrupting adjacent readings.

  • Engineers add imputation first (to handle missing data), then later realize they need outlier detection.
  • By then, the pipeline order is established and changing it requires refactoring.
Forward Fill: gap=${fwd_gapLen} samples, max_gap=${fwd_maxGap} ${gapShade} ${[yMin, (yMin + yMax) / 2, yMax].map(v => `${v.toFixed(1)}`).join("")} ${origDots} ${imputedDots} Sample Index Original data Forward-filled Gap too large (rejected)
iotclass.org

Deck summary

Key takeaways

The analyst can carry the last value forward, draw a line across the gap, or leave it empty.

  • A later repair may support review or study, but it must not silently rewrite the record used for a safety action.
  • Missing and noisy sensor readings corrupt every downstream analysis, making data imputation (filling gaps) and filtering (smoothing noise) essential preprocessing steps before any IoT analytics pipeline can produce reliable results.
  • Missing data and noise are inevitable in real IoT deployments.: Sensors lose power, networks drop packets, and electronic noise corrupts readings.
  • The first half of the chapter is about deciding what a gap means.
iotclass.org

Retrieval practice

Recall check 1 of 5

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

Q1A PIR motion sensor loses 30 seconds of data during a brief network outage. What is the most appropriate imputation choice?

AFill the gap with zero (no motion), which matches the sensor's default resting state
BLinearly interpolate between the readings before and after the gap
CForward-fill the last value, holding whatever state preceded the outage
DDrop the entire day's record so no assumption is made about the gap
Show answer

Answer: A Imputation must respect signal semantics; a missing PIR event maps to no motion (zero), not interpolation.

iotclass.org

Retrieval practice

Recall check 2 of 5

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

Q2A motion sensor (PIR) has 30 seconds of missing data due to a network outage. What is the most appropriate imputation strategy?

AUse zero (no motion) for all missing values
BForward-fill from the last valid reading
CLinear interpolation between before and after values
DDrop the entire 30-second period from analysis
Show answer

Answer: A For event-driven sensors like PIR motion detectors, zero (no motion) is the correct imputation.

iotclass.org

Retrieval practice

Recall check 3 of 5

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

Q3A humidity sensor shows 10 consecutive readings of exactly 78.00%. What quality concern does this indicate?

ANo concern - the environment is simply stable
BRange violation - humidity cannot be exactly 78%
CNoise filtering is working too aggressively
DStuck sensor - zero variance is suspicious
Show answer

Answer: D Real analog sensors always have some noise - even in stable environments, readings fluctuate by at least the ADC resolution.

iotclass.org

Retrieval practice

Recall check 4 of 5

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

Q4You have a pressure sensor with occasional spike readings of 0 or 4095 (ADC limits) due to electrical interference. Which filter is best?

AMoving average - will smooth out the spikes
BMedian filter - completely ignores spike outliers
CExponential smoothing - weights recent values more
DKalman filter - optimal for all signal types
Show answer

Answer: B The median filter is ideal for spike removal because it completely ignores outliers.

Q5Place each data-repair responsibility where it lives so you can repair missing or noisy readings without hiding which values were observed and which were inferred.

AMissingness and Quality Flags
BBounded Imputation
CNoise Filter
DValidated Dataset with Lineage
Show answer

Answer: A repair missing or noisy readings without hiding which values were observed and which were inferred.

iotclass.org

Retrieval practice

Recall check 5 of 5

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

Q6Complete 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

Print reference

Answers 1 of 2

Answer key.

  1. A · Imputation must respect signal semantics; a missing PIR event maps to no motion (zero), not interpolation.
  2. A · For event-driven sensors like PIR motion detectors, zero (no motion) is the correct imputation.
  3. D · Real analog sensors always have some noise - even in stable environments, readings fluctuate by at least the ADC resolution.
  4. B · The median filter is ideal for spike removal because it completely ignores outliers.
iotclass.org

Print reference

Answers 2 of 2

Answer key.

  1. A · repair missing or noisy readings without hiding which values were observed and which were inferred.
  2. A · Sensor data cleaning validates physical limits while preserving missing markers, then interpolates the gaps and smooths with an exponential moving average.
iotclass.org