Towards plausibility in time series counterfactual explanations

This paper introduces a gradient-based optimization method for generating time series counterfactual explanations that ensures plausibility by integrating soft-DTW alignment with k-nearest neighbors, resulting in valid and temporally realistic outputs that outperform existing approaches in distributional alignment.

Marcin Kostrzewa, Krzysztof Galus, Maciej Zi\k{e}ba

Published Tue, 10 Ma
📖 4 min read☕ Coffee break read

Imagine you have a very smart, but somewhat mysterious, robot doctor. This robot looks at your heart rate monitor (a time series) and says, "You have a heart condition."

You ask, "Why?" The robot says, "Because of the pattern." But that's not helpful. You want to know: "What is the minimum change I need to make to my heart rhythm so that the robot would say, 'You are healthy' instead?"

This is what the paper calls a Counterfactual Explanation. It's like asking, "What if I had done X instead of Y?"

The Problem: The "Fake" Heartbeat

The authors found that existing methods for answering this question often create "fake" heartbeats.

Imagine you are trying to explain to a friend how to fix a broken clock.

  • Old methods might say: "Just take the gears out and glue them back on in a random order that looks like a clock." Technically, it might tick, but it looks weird and unnatural. If you tried to build a real clock that way, it would be a disaster.
  • In the world of data, these methods create "adversarial" patterns—tiny, weird glitches that trick the robot into changing its mind, but they don't look like anything a real human heart (or stock market, or factory machine) would ever actually do. They lack plausibility.

The Solution: The "Realistic" Makeover

The authors, Marcin, Krzysztof, and Maciej, built a new tool that acts like a talented stylist rather than a random glitch generator.

Here is how their method works, using a simple analogy:

1. The Goal: A Valid Change

First, the tool must change the input (your heart rate) just enough so the robot changes its prediction from "Sick" to "Healthy." This is the Validity check.

2. The Secret Sauce: The "Target Class" Dance Floor

This is the paper's big innovation. To make sure the new heart rate looks real, the tool doesn't just guess. It goes to a "dance floor" filled with thousands of examples of healthy heartbeats (the target class).

It picks the 10 closest healthy heartbeats to your current one. Think of these as your "role models."

3. The Soft-DTW: The Flexible Ruler

Usually, comparing two heartbeats is like comparing two lines of text word-for-word. If one heartbeat is slightly faster or slower than the other, a standard ruler says they are totally different.

The authors use a special tool called Soft-DTW (Dynamic Time Warping).

  • Analogy: Imagine two people dancing to the same song, but one is slightly ahead of the beat. A standard ruler would say, "You are out of sync!"
  • Soft-DTW is like a flexible, stretchy ruler. It says, "You are dancing the same moves, just at a slightly different speed. You are still in sync."
  • The tool uses this flexible ruler to gently nudge your "sick" heartbeat until it looks like it belongs in the same dance circle as the "healthy" role models.

The Trade-off: Comfort vs. Style

The paper admits there is a catch.

  • Old methods try to change as little as possible (minimal effort), even if the result looks weird.
  • The new method is willing to make a bigger change to the data if it means the result looks realistic.

Analogy:
Imagine you want to turn a square peg into a round one.

  • Old method: You shave off a tiny corner. It's still a square peg, but the robot thinks it's round because of a trick. It's a "cheap" fix.
  • New method: You shave off more wood to make it a perfect circle. It takes more work (more "distance" from the original), but it's a real round peg that fits perfectly in the hole.

Why Does This Matter?

If you are a doctor, a financial analyst, or a factory manager, you don't want to be told, "If you change your data by this weird, impossible amount, you'll be safe." You want to know, "If I adjust my process to look more like a healthy example, will I be safe?"

This new method ensures that the "what-if" scenarios it generates are plausible. They aren't just mathematically correct; they are realistic and could actually happen in the real world.

Summary

  • The Problem: Current AI explanations for time-series data often create fake, unrealistic scenarios.
  • The Fix: A new method that gently reshapes the data to look like real examples from the "good" category, using a flexible comparison tool (Soft-DTW).
  • The Result: Explanations that are trustworthy because they respect the natural rhythm and structure of the data, even if they require a slightly bigger change to get there.