CBR-FoX is a Python library designed to provide case-based reasoning explanations for time series prediction models. This approach enhances the transparency and interpretability of machine learning models applied to sequential data through explainable AI capabilities.
- Features
- Installation
- Quick Start
- Usage Workflow
- Documentation
- Architecture
- Citation
- Support
- Operating Environment
- License
- Contributing
- Acknowledgments
- Case-Based Reasoning (CBR) Implementation: Utilizes case-based reasoning to enhance explainability in time series predictions
- Multiple Distance Metrics: DTW, Euclidean, Pearson correlation, and custom CCI metric
- Explainable AI: Visualize and understand case selection process with clear, human-readable insights
- Flexible Architecture: Easy integration with custom metrics via sktime adapter
- Versatile & Adaptable: Supports various types of time series data (univariate, multivariate)
- ML Model Compatibility: Easily integrates with common machine learning models
- Comprehensive Visualization: Built-in plotting utilities with matplotlib and plotly
- Production Ready: Fully tested, documented, and containerized
pip install CBR-FoXconda env create -f environment.yml
conda activate cbr_fox# Clone the repository
git clone https://github.com/aaaimx/CBR-FoX.git
cd CBR-FoX
# Install required dependencies
pip install -r requirements.txt
# Install in development mode
pip install -e .# Build and run with docker-compose
docker-compose up cbr_fox
# Or run directly
docker build -t cbr_fox .
docker run cbr_fox python scripts/examples/reproduce_all_figures.pyfrom cbr_fox.core import cbr_fox
from cbr_fox.builder import cbr_fox_builder
import numpy as np
# Create sample data
# training_windows: shape [n_windows, window_len, n_features]
training_windows = np.random.randn(100, 24, 3)
target_windows = np.random.randn(100, 3)
forecast_window = np.random.randn(24, 3)
# Initialize CBR with DTW metric
cbr = cbr_fox(metric="dtw", smoothness_factor=0.2)
# Fit and predict
cbr.fit(training_windows, target_windows, forecast_window)
prediction = np.random.randn(3)
cbr.predict(prediction, num_cases=5, mode="simple")
# Get analysis report
report = cbr.get_analysis_report()
print(report)
# Visualize results
from cbr_fox.utils import plot_utils
plot_utils.visualize_pyplot(cbr)Follow these steps to use CBR-FoX in your projects:
Extract the relevant inputs and outputs from your AI model:
# Get your model's training windows, targets, and forecasts
training_windows = model.get_training_windows() # shape: [n_windows, window_len, n_features]
target_windows = model.get_targets() # shape: [n_windows, n_features]
forecast_window = model.get_current_window() # shape: [window_len, n_features]
prediction = model.predict() # shape: [n_features]from cbr_fox.core import cbr_fox
# Single metric instance
cbr_instance = cbr_fox(metric="dtw", smoothness_factor=0.2)
# Or multiple instances for comparison
cbr_dtw = cbr_fox(metric="dtw")
cbr_euclidean = cbr_fox(metric="euclidean")
cbr_cci = cbr_fox(metric="cci_distance", kwargs={"punishedSumFactor": 0.5})from cbr_fox.builder import cbr_fox_builder
# Create builder with multiple techniques
builder = cbr_fox_builder([cbr_dtw, cbr_euclidean, cbr_cci])# Single instance
cbr_instance.fit(training_windows, target_windows, forecast_window)
# Or with builder
builder.fit(training_windows, target_windows, forecast_window)# Single instance
cbr_instance.predict(prediction=prediction, num_cases=5, mode="simple")
report = cbr_instance.get_analysis_report()
# Or with builder
builder.predict(prediction=prediction, num_cases=5, mode="simple")# Single instance visualization
plot_utils.visualize_pyplot(
cbr_instance,
fmt='--d',
scatter_params={'s': 50},
xtick_rotation=50,
title='CBR-FoX Analysis',
xlabel='Time Steps',
ylabel='Values'
)
# Or with builder (compares all techniques)
builder.visualize_pyplot(
mode="individual", # or "combined"
fmt='--o',
title='Multi-Metric Comparison'
)Full documentation is available at https://cbr-fox.readthedocs.io
To reproduce all figures from the publication:
python scripts/examples/reproduce_all_figures.py --output-dir figuresIndividual figures can be generated using:
python scripts/examples/figure_1_architecture.py
python scripts/examples/figure_5_metric_comparison.pyThe following diagram illustrates the typical workflow of CBR-FoX, from retrieving AI model outputs to generating visual explanations:
Detailed class relationships and module dependencies:
classDiagram
class cbr_fox {
+metric: Union[str, Callable]
+fit(training_windows, target_windows, forecast_window)
+predict(prediction, num_cases, mode)
+get_analysis_report() DataFrame
}
class cbr_fox_builder {
+techniques: List[cbr_fox]
+fit(training_windows, target_windows, forecast_window)
+predict(prediction, num_cases, mode)
+visualize_pyplot(mode)
}
class sktime_interface {
+compute_distance_interface(input_dict, metric, kwargs)
}
cbr_fox_builder --> cbr_fox
cbr_fox --> sktime_interface
The following diagram represents the core classes and their interactions within the library:
For detailed architecture documentation including type hints and interface specifications, see the Architecture Documentation.
If you use CBR-FoX in your research, please cite:
@article{cbr_fox2025,
title = {CBR-FoX: A Python Framework for Case-Based Reasoning in Time Series Forecasting},
author = {Gerardo A. Pérez-Pérez and
Moisés F. Valdez-Ávila and
Mauricio G. Orozco-del-Castillo and
Carlos Bermejo-Sabbagh and
Juan A. Recio-García},
journal = {SoftwareX},
year = {2025},
pages = {15},
url = {https://github.com/aaaimx/CBR-FoX}
}[Your Name]. (2025). CBR-FoX: A Python Framework for Case-Based Reasoning
in Time Series Forecasting. SoftwareX, [Volume]([Issue]), [Pages].
https://doi.org/[DOI]
For the software itself, please also cite:
@software{cbr_fox_software,
author = {Gerardo A. Pérez-Pérez and
Moisés F. Valdez-Ávila and
Mauricio G. Orozco-del-Castillo and
Carlos Bermejo-Sabbagh and
Juan A. Recio-García},
title = {CBR-FoX: Case-Based Reasoning for Time Series Forecasting},
year = {2025},
version = {1.0.1},
url = {https://github.com/aaaimx/CBR-FoX},
doi = {10.5281/zenodo.XXXXXXX}
}See CITATION.cff for machine-readable citation metadata.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Read the Docs
- Email: your-email@example.com
| Platform | Versions | Status |
|---|---|---|
| Linux | Ubuntu 20.04+, Debian 10+, CentOS 8+ | ✅ Fully Supported |
| macOS | 11 (Big Sur) and later | ✅ Fully Supported |
| Windows | 10, 11 | ✅ Fully Supported |
- Minimum Python Version: 3.9
- Recommended: Python 3.11
- Maximum Tested: Python 3.12
All dependencies are pinned in requirements.txt and environment.yml for reproducibility. Key dependencies include:
- NumPy >= 1.24.0, < 2.1.0
- SciPy >= 1.10.0, < 1.14.0
- pandas >= 2.0.0, < 2.4.0
- scikit-learn >= 1.3.0, < 1.7.0
- sktime == 0.38.5
- matplotlib >= 3.7.0, < 3.10.0
- statsmodels >= 0.14.0, < 0.15.0
See NOTICE for third-party license information.
# Run tests to verify installation
pytest tests/ -v
# Check coverage
pytest tests/ --cov=cbr_fox --cov-report=htmlThis project is licensed under the European Union Public Licence (EUPL) v. 1.2.
- License: EUPL-1.2
- SPDX:
EUPL-1.2 - OSI Approved: Yes
- Compatible with: GPL, MIT, BSD, Apache, MPL
All third-party dependencies have been verified for EUPL 1.2 compatibility. See NOTICE for detailed license information of all dependencies.
EUPL allows commercial use, modification, and distribution under the same license (copyleft). For specific use cases, please review the full license text.
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Key areas for contribution:
- New distance metrics
- Visualization enhancements
- Documentation improvements
- Bug reports and fixes
- Performance optimizations
This work was supported by [Your Funding Source/Institution].
Special thanks to:
- The sktime community for their excellent time series toolkit
- The scikit-learn community for machine learning foundations
- All contributors and users of CBR-FoX
Maintained by: AAAIMX
Institution: AAAIMX - Advanced Analytics and AI Research Group
Repository: https://github.com/aaaimx/CBR-FoX
Last Updated: October 2025