eb-adapters 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2025, Kyle Corrie
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,182 @@
1
+ Metadata-Version: 2.4
2
+ Name: eb-adapters
3
+ Version: 0.1.0
4
+ Summary: Adapter layer for third-party forecasting libraries in Electric Barometer
5
+ License: BSD-3-Clause
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: numpy
10
+ Requires-Dist: pandas
11
+ Provides-Extra: prophet
12
+ Requires-Dist: prophet>=1.1; extra == "prophet"
13
+ Provides-Extra: statsmodels
14
+ Requires-Dist: statsmodels>=0.14; extra == "statsmodels"
15
+ Provides-Extra: catboost
16
+ Requires-Dist: catboost>=1.2; extra == "catboost"
17
+ Provides-Extra: lightgbm
18
+ Requires-Dist: lightgbm>=4.0; extra == "lightgbm"
19
+ Provides-Extra: dev
20
+ Requires-Dist: pytest; extra == "dev"
21
+ Requires-Dist: pytest-cov; extra == "dev"
22
+ Requires-Dist: mypy; extra == "dev"
23
+ Requires-Dist: ruff; extra == "dev"
24
+ Dynamic: license-file
25
+
26
+ # Electric Barometer Adapters (`eb-adapters`)
27
+
28
+ ![License: BSD-3-Clause](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)
29
+ ![Python Versions](https://img.shields.io/badge/Python-3.10%2B-blue)
30
+ [![Docs](https://img.shields.io/badge/docs-electric--barometer-blue)](https://economistician.github.io/eb-docs/)
31
+ ![Project Status](https://img.shields.io/badge/Status-Alpha-yellow)
32
+
33
+ This repository contains the **model adapter layer** of the *Electric Barometer*
34
+ ecosystem.
35
+
36
+ `eb-adapters` provides standardized interfaces that adapt common forecasting and
37
+ machine-learning libraries to the Electric Barometer evaluation and readiness
38
+ frameworks, enabling consistent metric computation and model comparison across
39
+ heterogeneous modeling approaches.
40
+
41
+ Conceptual definitions and evaluation philosophy are maintained in the companion
42
+ research repository:
43
+ **`eb-papers`**.
44
+
45
+ ---
46
+
47
+ ## Naming convention
48
+
49
+ Electric Barometer packages follow standard Python packaging conventions:
50
+
51
+ - **Distribution names** (used with `pip install`) use hyphens
52
+ e.g. `pip install eb-adapters`
53
+ - **Python import paths** use underscores
54
+ e.g. `import eb_adapters`
55
+
56
+ This distinction is intentional and consistent across the Electric Barometer
57
+ ecosystem.
58
+
59
+ ---
60
+
61
+ ## Role Within Electric Barometer
62
+
63
+ Within the Electric Barometer ecosystem:
64
+
65
+ - **`eb-papers`** defines *concepts, frameworks, and meaning*
66
+ - **`eb-metrics`** implements *individual metrics*
67
+ - **`eb-evaluation`** orchestrates *evaluation workflows*
68
+ - **`eb-adapters`** standardizes *model interfaces*
69
+
70
+ This repository focuses on bridging external modeling libraries into a common,
71
+ evaluation-ready form.
72
+
73
+ ---
74
+
75
+ ## What This Library Provides
76
+
77
+ - **A common adapter base class** defining a unified interface for forecast models
78
+ - **Library-specific adapters** for popular forecasting and ML frameworks
79
+ - **Consistent prediction and evaluation hooks** compatible with EB metrics
80
+ - **Extensible patterns** for adding new model families without changing
81
+ downstream evaluation logic
82
+
83
+ Current adapters include support for:
84
+ - CatBoost
85
+ - LightGBM
86
+ - Prophet
87
+ - Statsmodels-based models
88
+
89
+ ---
90
+
91
+ ## Scope
92
+
93
+ This repository focuses on **model adaptation**, not model training algorithms or
94
+ metric definitions.
95
+
96
+ **In scope:**
97
+ - Wrapping external model APIs behind a consistent adapter interface
98
+ - Standardizing prediction outputs for evaluation
99
+ - Providing compatibility with EB evaluation pipelines
100
+
101
+ **Out of scope:**
102
+ - Metric definitions and loss formulations (see `eb-metrics`)
103
+ - Evaluation orchestration logic (see `eb-evaluation`)
104
+ - Model training methodology or hyperparameter optimization
105
+ - Conceptual framework definitions (see `eb-papers`)
106
+
107
+ ---
108
+
109
+ ## Installation
110
+
111
+ Install from PyPI:
112
+
113
+ ```bash
114
+ pip install eb-adapters
115
+ ```
116
+
117
+ For development or local use:
118
+
119
+ ```bash
120
+ pip install -e .
121
+ ```
122
+
123
+ ---
124
+
125
+ ## Package Structure
126
+
127
+ The repository follows a clean, modern Python package layout:
128
+
129
+ ```text
130
+ eb-adapters/
131
+ ├── src/eb_adapters/
132
+ │ ├── base.py # Abstract adapter base class
133
+ │ ├── catboost.py # CatBoost model adapter
134
+ │ ├── lightgbm.py # LightGBM model adapter
135
+ │ ├── prophet.py # Prophet model adapter
136
+ │ └── statsmodels.py # Statsmodels-based adapters
137
+
138
+ ├── tests/
139
+ │ └── adapters/ # Unit tests for adapter implementations
140
+
141
+ ├── pyproject.toml # Build and dependency configuration
142
+ ├── README.md # Project documentation
143
+ └── LICENSE # BSD-3-Clause license
144
+ ```
145
+
146
+ ---
147
+
148
+ ## Relationship to Other EB Repositories
149
+
150
+ - **`eb-papers`**
151
+ Source of truth for conceptual definitions and evaluation philosophy.
152
+
153
+ - **`eb-metrics`**
154
+ Provides the metric implementations used during evaluation.
155
+
156
+ - **`eb-evaluation`**
157
+ Orchestrates evaluation workflows using adapted models.
158
+
159
+ - **`eb-adapters`**
160
+ Ensures heterogeneous models can be evaluated consistently.
161
+
162
+ When discrepancies arise, conceptual intent in `eb-papers` should be treated as
163
+ authoritative.
164
+
165
+ ---
166
+
167
+ ## Development and Testing
168
+
169
+ Tests are located under the `tests/` directory and mirror adapter coverage.
170
+
171
+ To run the test suite:
172
+
173
+ ```bash
174
+ pytest
175
+ ```
176
+
177
+ ---
178
+
179
+ ## Status
180
+
181
+ This package is under active development.
182
+ Public APIs may evolve prior to the first stable release.
@@ -0,0 +1,157 @@
1
+ # Electric Barometer Adapters (`eb-adapters`)
2
+
3
+ ![License: BSD-3-Clause](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)
4
+ ![Python Versions](https://img.shields.io/badge/Python-3.10%2B-blue)
5
+ [![Docs](https://img.shields.io/badge/docs-electric--barometer-blue)](https://economistician.github.io/eb-docs/)
6
+ ![Project Status](https://img.shields.io/badge/Status-Alpha-yellow)
7
+
8
+ This repository contains the **model adapter layer** of the *Electric Barometer*
9
+ ecosystem.
10
+
11
+ `eb-adapters` provides standardized interfaces that adapt common forecasting and
12
+ machine-learning libraries to the Electric Barometer evaluation and readiness
13
+ frameworks, enabling consistent metric computation and model comparison across
14
+ heterogeneous modeling approaches.
15
+
16
+ Conceptual definitions and evaluation philosophy are maintained in the companion
17
+ research repository:
18
+ **`eb-papers`**.
19
+
20
+ ---
21
+
22
+ ## Naming convention
23
+
24
+ Electric Barometer packages follow standard Python packaging conventions:
25
+
26
+ - **Distribution names** (used with `pip install`) use hyphens
27
+ e.g. `pip install eb-adapters`
28
+ - **Python import paths** use underscores
29
+ e.g. `import eb_adapters`
30
+
31
+ This distinction is intentional and consistent across the Electric Barometer
32
+ ecosystem.
33
+
34
+ ---
35
+
36
+ ## Role Within Electric Barometer
37
+
38
+ Within the Electric Barometer ecosystem:
39
+
40
+ - **`eb-papers`** defines *concepts, frameworks, and meaning*
41
+ - **`eb-metrics`** implements *individual metrics*
42
+ - **`eb-evaluation`** orchestrates *evaluation workflows*
43
+ - **`eb-adapters`** standardizes *model interfaces*
44
+
45
+ This repository focuses on bridging external modeling libraries into a common,
46
+ evaluation-ready form.
47
+
48
+ ---
49
+
50
+ ## What This Library Provides
51
+
52
+ - **A common adapter base class** defining a unified interface for forecast models
53
+ - **Library-specific adapters** for popular forecasting and ML frameworks
54
+ - **Consistent prediction and evaluation hooks** compatible with EB metrics
55
+ - **Extensible patterns** for adding new model families without changing
56
+ downstream evaluation logic
57
+
58
+ Current adapters include support for:
59
+ - CatBoost
60
+ - LightGBM
61
+ - Prophet
62
+ - Statsmodels-based models
63
+
64
+ ---
65
+
66
+ ## Scope
67
+
68
+ This repository focuses on **model adaptation**, not model training algorithms or
69
+ metric definitions.
70
+
71
+ **In scope:**
72
+ - Wrapping external model APIs behind a consistent adapter interface
73
+ - Standardizing prediction outputs for evaluation
74
+ - Providing compatibility with EB evaluation pipelines
75
+
76
+ **Out of scope:**
77
+ - Metric definitions and loss formulations (see `eb-metrics`)
78
+ - Evaluation orchestration logic (see `eb-evaluation`)
79
+ - Model training methodology or hyperparameter optimization
80
+ - Conceptual framework definitions (see `eb-papers`)
81
+
82
+ ---
83
+
84
+ ## Installation
85
+
86
+ Install from PyPI:
87
+
88
+ ```bash
89
+ pip install eb-adapters
90
+ ```
91
+
92
+ For development or local use:
93
+
94
+ ```bash
95
+ pip install -e .
96
+ ```
97
+
98
+ ---
99
+
100
+ ## Package Structure
101
+
102
+ The repository follows a clean, modern Python package layout:
103
+
104
+ ```text
105
+ eb-adapters/
106
+ ├── src/eb_adapters/
107
+ │ ├── base.py # Abstract adapter base class
108
+ │ ├── catboost.py # CatBoost model adapter
109
+ │ ├── lightgbm.py # LightGBM model adapter
110
+ │ ├── prophet.py # Prophet model adapter
111
+ │ └── statsmodels.py # Statsmodels-based adapters
112
+
113
+ ├── tests/
114
+ │ └── adapters/ # Unit tests for adapter implementations
115
+
116
+ ├── pyproject.toml # Build and dependency configuration
117
+ ├── README.md # Project documentation
118
+ └── LICENSE # BSD-3-Clause license
119
+ ```
120
+
121
+ ---
122
+
123
+ ## Relationship to Other EB Repositories
124
+
125
+ - **`eb-papers`**
126
+ Source of truth for conceptual definitions and evaluation philosophy.
127
+
128
+ - **`eb-metrics`**
129
+ Provides the metric implementations used during evaluation.
130
+
131
+ - **`eb-evaluation`**
132
+ Orchestrates evaluation workflows using adapted models.
133
+
134
+ - **`eb-adapters`**
135
+ Ensures heterogeneous models can be evaluated consistently.
136
+
137
+ When discrepancies arise, conceptual intent in `eb-papers` should be treated as
138
+ authoritative.
139
+
140
+ ---
141
+
142
+ ## Development and Testing
143
+
144
+ Tests are located under the `tests/` directory and mirror adapter coverage.
145
+
146
+ To run the test suite:
147
+
148
+ ```bash
149
+ pytest
150
+ ```
151
+
152
+ ---
153
+
154
+ ## Status
155
+
156
+ This package is under active development.
157
+ Public APIs may evolve prior to the first stable release.
@@ -0,0 +1,26 @@
1
+ [project]
2
+ name = "eb-adapters"
3
+ version = "0.1.0"
4
+ description = "Adapter layer for third-party forecasting libraries in Electric Barometer"
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ license = { text = "BSD-3-Clause" }
8
+ dependencies = [
9
+ "numpy",
10
+ "pandas", # only really needed for Prophet adapter
11
+ ]
12
+
13
+ [project.optional-dependencies]
14
+ prophet = ["prophet>=1.1"]
15
+ statsmodels = ["statsmodels>=0.14"]
16
+ catboost = ["catboost>=1.2"]
17
+ lightgbm = ["lightgbm>=4.0"]
18
+ dev = [
19
+ "pytest",
20
+ "pytest-cov",
21
+ "mypy",
22
+ "ruff",
23
+ ]
24
+
25
+ [tool.setuptools.packages.find]
26
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,34 @@
1
+ from __future__ import annotations
2
+
3
+ """
4
+ eb_adapters.
5
+
6
+ Adapter classes for integrating external forecasting and regression engines
7
+ (Prophet, statsmodels, CatBoost, LightGBM, etc.) into the ElectricBarometer
8
+ ecosystem using a consistent scikit-learn-like interface.
9
+
10
+ All adapters exposed by this package implement:
11
+
12
+ - `fit(X, y, sample_weight=None)` returning `self`
13
+ - `predict(X)` returning a one-dimensional numpy array
14
+
15
+ This allows ElectricBarometer evaluation, selection, and cloning utilities to
16
+ treat native scikit-learn estimators and wrapped external models uniformly.
17
+ """
18
+
19
+ from .base import BaseAdapter, _clone_model, clone_model
20
+ from .prophet import ProphetAdapter
21
+ from .statsmodels import SarimaxAdapter, ArimaAdapter
22
+ from .catboost import CatBoostAdapter
23
+ from .lightgbm import LightGBMRegressorAdapter
24
+
25
+ __all__ = [
26
+ "BaseAdapter",
27
+ "_clone_model",
28
+ "clone_model",
29
+ "ProphetAdapter",
30
+ "SarimaxAdapter",
31
+ "ArimaAdapter",
32
+ "CatBoostAdapter",
33
+ "LightGBMRegressorAdapter",
34
+ ]
@@ -0,0 +1,151 @@
1
+ from __future__ import annotations
2
+
3
+ """
4
+ Base adapter interfaces and cloning utilities.
5
+
6
+ This module defines the minimal adapter contract used throughout the
7
+ ElectricBarometer ecosystem, along with a lightweight cloning helper for
8
+ estimator-like objects.
9
+
10
+ Adapters are intended to wrap non-scikit-learn forecasting or regression
11
+ libraries (for example, statsmodels, Prophet, or custom models) and expose
12
+ a scikit-learn-like interface so they can be used interchangeably inside
13
+ ElectricBarometer evaluation and selection workflows.
14
+ """
15
+
16
+ from typing import Any, Optional
17
+
18
+ import numpy as np
19
+
20
+
21
+ def _clone_model(model: Any) -> Any:
22
+ """
23
+ Lightweight cloning utility for estimator-like or adapter-like objects.
24
+
25
+ This function attempts to reconstruct a fresh instance of a model using a
26
+ best-effort strategy that favors compatibility with scikit-learn-style APIs
27
+ while remaining usable for custom adapters.
28
+
29
+ Cloning strategy
30
+ ----------------
31
+ The following steps are attempted in order:
32
+
33
+ 1. If scikit-learn is available, call `sklearn.base.clone(model)`.
34
+ 2. Otherwise, if the object implements `get_params()`, re-instantiate via::
35
+
36
+ model.__class__(**model.get_params())
37
+
38
+ 3. As a final fallback, instantiate the class with no arguments::
39
+
40
+ model.__class__()
41
+
42
+ Notes
43
+ -----
44
+ For custom adapters, the most reliable approach is to make the adapter
45
+ configuration-only at initialization time and implement `get_params()`
46
+ so that the instance can be reconstructed deterministically.
47
+
48
+ If a model cannot be meaningfully cloned using parameters alone, callers
49
+ may choose to bypass this helper and explicitly construct fresh adapter
50
+ instances before passing them into ElectricBarometer workflows.
51
+ """
52
+ # Try sklearn.clone if available
53
+ try: # pragma: no cover - optional dependency path
54
+ from sklearn.base import clone as sk_clone # type: ignore
55
+
56
+ return sk_clone(model)
57
+ except Exception:
58
+ pass
59
+
60
+ # Fallback: re-create via class + get_params
61
+ if hasattr(model, "get_params"):
62
+ try:
63
+ params = model.get_params() # type: ignore[assignment]
64
+ return model.__class__(**params)
65
+ except Exception:
66
+ # If get_params exists but reconstruction fails, fall through
67
+ # to the final fallback below.
68
+ pass
69
+
70
+ # Last resort: call class with no args
71
+ return model.__class__()
72
+
73
+
74
+ # Optional public alias for convenience / backwards compatibility
75
+ clone_model = _clone_model
76
+
77
+
78
+ class BaseAdapter:
79
+ """
80
+ Minimal base class defining the adapter contract for ElectricBarometer.
81
+
82
+ This class documents the expected interface for wrapping non-scikit-learn
83
+ forecasting or regression engines so they can be evaluated and selected
84
+ alongside native scikit-learn estimators.
85
+
86
+ Subclasses are expected to present a scikit-learn-like API:
87
+
88
+ - `fit(X, y, sample_weight=None)` returning `self`
89
+ - `predict(X)` returning a one-dimensional numpy array
90
+
91
+ The ElectricBarometer engine does not distinguish between native
92
+ scikit-learn estimators and adapters; it simply calls `fit` and `predict`.
93
+ This base class serves as a clear, documented contract for adapter authors.
94
+ """
95
+
96
+ def fit(
97
+ self,
98
+ X: np.ndarray,
99
+ y: np.ndarray,
100
+ sample_weight: Optional[np.ndarray] = None,
101
+ ) -> "BaseAdapter":
102
+ """
103
+ Fit the underlying forecasting or regression model.
104
+
105
+ Parameters
106
+ ----------
107
+ X : numpy.ndarray
108
+ Feature matrix. For pure time-series models, this may be ignored
109
+ or used only for alignment.
110
+ y : numpy.ndarray
111
+ One-dimensional target vector.
112
+ sample_weight : numpy.ndarray | None
113
+ Optional per-sample weights. Adapters may ignore this argument if
114
+ weighting is not supported by the underlying model.
115
+
116
+ Returns
117
+ -------
118
+ BaseAdapter
119
+ The fitted adapter instance (self).
120
+
121
+ Raises
122
+ ------
123
+ NotImplementedError
124
+ If the subclass does not override this method.
125
+ """
126
+ raise NotImplementedError(
127
+ "BaseAdapter subclasses must implement fit(X, y, sample_weight=None)."
128
+ )
129
+
130
+ def predict(self, X: np.ndarray) -> np.ndarray:
131
+ """
132
+ Generate predictions from the fitted model.
133
+
134
+ Parameters
135
+ ----------
136
+ X : numpy.ndarray
137
+ Feature matrix used to generate predictions.
138
+
139
+ Returns
140
+ -------
141
+ numpy.ndarray
142
+ One-dimensional array of predictions.
143
+
144
+ Raises
145
+ ------
146
+ NotImplementedError
147
+ If the subclass does not override this method.
148
+ """
149
+ raise NotImplementedError(
150
+ "BaseAdapter subclasses must implement predict(X)."
151
+ )