  Deep learning models are widely used in traffic forecasting and have achieved
state-of-the-art prediction accuracy. However, the black-box nature of those
models makes the results difficult to interpret by users. This study aims to
leverage an Explainable AI approach, counterfactual explanations, to enhance
the explainability and usability of deep learning-based traffic forecasting
models. Specifically, the goal is to elucidate relationships between various
input contextual features and their corresponding predictions. We present a
comprehensive framework that generates counterfactual explanations for traffic
forecasting and provides usable insights through the proposed scenario-driven
counterfactual explanations. The study first implements a deep learning model
to predict traffic speed based on historical traffic data and contextual
variables. Counterfactual explanations are then used to illuminate how
alterations in these input variables affect predicted outcomes, thereby
enhancing the transparency of the deep learning model. We investigated the
impact of contextual features on traffic speed prediction under varying spatial
and temporal conditions. The scenario-driven counterfactual explanations
integrate two types of user-defined constraints, directional and weighting
constraints, to tailor the search for counterfactual explanations to specific
use cases. These tailored explanations benefit machine learning practitioners
who aim to understand the model's learning mechanisms and domain experts who
seek insights for real-world applications. The results showcase the
effectiveness of counterfactual explanations in revealing traffic patterns
learned by deep learning models, showing its potential for interpreting
black-box deep learning models used for spatiotemporal predictions in general.
