skdr-eval 0.1.1__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,22 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ insert_final_newline = true
7
+ trim_trailing_whitespace = true
8
+
9
+ [*.{py,pyi}]
10
+ indent_style = space
11
+ indent_size = 4
12
+
13
+ [*.{yml,yaml}]
14
+ indent_style = space
15
+ indent_size = 2
16
+
17
+ [*.{json,toml}]
18
+ indent_style = space
19
+ indent_size = 2
20
+
21
+ [*.md]
22
+ trim_trailing_whitespace = false
@@ -0,0 +1,83 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main, develop ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.9", "3.10", "3.11", "3.12"]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ with:
19
+ fetch-depth: 0 # Needed for setuptools_scm
20
+
21
+ - name: Set up Python ${{ matrix.python-version }}
22
+ uses: actions/setup-python@v5
23
+ with:
24
+ python-version: ${{ matrix.python-version }}
25
+
26
+ - name: Install dependencies
27
+ run: |
28
+ python -m pip install --upgrade pip
29
+ pip install -e .[dev]
30
+
31
+ - name: Lint with ruff
32
+ run: |
33
+ ruff check src/ tests/ examples/
34
+ ruff format --check src/ tests/ examples/
35
+
36
+ - name: Type check with mypy
37
+ run: |
38
+ mypy src/skdr_eval/
39
+
40
+ - name: Test with pytest
41
+ run: |
42
+ pytest -v --cov=skdr_eval --cov-report=xml --cov-report=html --cov-report=term-missing
43
+
44
+ - name: Upload coverage reports
45
+ uses: codecov/codecov-action@v3
46
+ with:
47
+ file: ./coverage.xml
48
+ flags: unittests
49
+ name: codecov-umbrella
50
+ fail_ci_if_error: false
51
+
52
+ build:
53
+ runs-on: ubuntu-latest
54
+ needs: test
55
+
56
+ steps:
57
+ - uses: actions/checkout@v4
58
+ with:
59
+ fetch-depth: 0 # Needed for setuptools_scm
60
+
61
+ - name: Set up Python
62
+ uses: actions/setup-python@v4
63
+ with:
64
+ python-version: "3.11"
65
+
66
+ - name: Install build dependencies
67
+ run: |
68
+ python -m pip install --upgrade pip
69
+ pip install build twine
70
+
71
+ - name: Build package
72
+ run: |
73
+ python -m build
74
+
75
+ - name: Check package
76
+ run: |
77
+ twine check dist/*
78
+
79
+ - name: Upload build artifacts
80
+ uses: actions/upload-artifact@v3
81
+ with:
82
+ name: dist
83
+ path: dist/
@@ -0,0 +1,69 @@
1
+ name: Release
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch: # Allow manual triggering
7
+
8
+ jobs:
9
+ build-and-publish:
10
+ runs-on: ubuntu-latest
11
+ environment: release
12
+ permissions:
13
+ id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
14
+
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ with:
18
+ fetch-depth: 0 # Needed for setuptools_scm
19
+
20
+ - name: Set up Python
21
+ uses: actions/setup-python@v5
22
+ with:
23
+ python-version: "3.11"
24
+
25
+ - name: Install build dependencies
26
+ run: |
27
+ python -m pip install --upgrade pip
28
+ pip install build twine
29
+
30
+ - name: Build package
31
+ run: |
32
+ python -m build
33
+
34
+ - name: Check package
35
+ run: |
36
+ twine check dist/*
37
+
38
+ - name: Publish to PyPI (Trusted Publishing)
39
+ id: pypi-publish
40
+ continue-on-error: true
41
+ uses: pypa/gh-action-pypi-publish@release/v1
42
+ with:
43
+ print-hash: true
44
+
45
+ - name: Fallback - Manual PyPI publish instructions
46
+ if: steps.pypi-publish.outcome == 'failure'
47
+ run: |
48
+ echo "❌ Trusted Publishing failed. Manual upload required."
49
+ echo ""
50
+ echo "To publish manually:"
51
+ echo "1. Download the build artifacts from this workflow"
52
+ echo "2. Set up your PyPI API token: https://pypi.org/manage/account/token/"
53
+ echo "3. Run: pip install twine"
54
+ echo "4. Run: twine upload dist/*"
55
+ echo ""
56
+ echo "For Trusted Publishing setup:"
57
+ echo "1. Go to https://pypi.org/manage/project/skdr-eval/settings/publishing/"
58
+ echo "2. Add this GitHub repository as a trusted publisher"
59
+ echo "3. Set environment name to 'release'"
60
+ echo "4. Set workflow filename to 'release.yml'"
61
+ echo ""
62
+ exit 1
63
+
64
+ - name: Upload build artifacts (for manual fallback)
65
+ if: always()
66
+ uses: actions/upload-artifact@v4
67
+ with:
68
+ name: dist-${{ github.run_number }}
69
+ path: dist/
@@ -0,0 +1,178 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be added to the global gitignore or merged into this project gitignore. For a PyCharm
158
+ # project, it is recommended to ignore the entire .idea directory.
159
+ .idea/
160
+
161
+ # VS Code
162
+ .vscode/
163
+
164
+ # macOS
165
+ .DS_Store
166
+
167
+ # Windows
168
+ Thumbs.db
169
+ ehthumbs.db
170
+ Desktop.ini
171
+
172
+ # Editor backups
173
+ *~
174
+ *.swp
175
+ *.swo
176
+
177
+ # Pre-commit
178
+ .pre-commit-config.yaml.bak
@@ -0,0 +1,29 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.4.0
4
+ hooks:
5
+ - id: trailing-whitespace
6
+ - id: end-of-file-fixer
7
+ - id: check-yaml
8
+ - id: check-added-large-files
9
+ - id: check-merge-conflict
10
+ - id: debug-statements
11
+
12
+ - repo: https://github.com/psf/black
13
+ rev: 23.7.0
14
+ hooks:
15
+ - id: black
16
+ language_version: python3
17
+
18
+ - repo: https://github.com/charliermarsh/ruff-pre-commit
19
+ rev: v0.0.287
20
+ hooks:
21
+ - id: ruff
22
+ args: [--fix, --exit-non-zero-on-fix]
23
+
24
+ - repo: https://github.com/pre-commit/mirrors-mypy
25
+ rev: v1.5.1
26
+ hooks:
27
+ - id: mypy
28
+ additional_dependencies: [types-all]
29
+ args: [--strict, --ignore-missing-imports]
@@ -0,0 +1,41 @@
1
+ line-length = 88
2
+ target-version = "py39"
3
+
4
+ [lint]
5
+ select = [
6
+ "E", # pycodestyle errors
7
+ "W", # pycodestyle warnings
8
+ "F", # pyflakes
9
+ "I", # isort
10
+ "B", # flake8-bugbear
11
+ "C4", # flake8-comprehensions
12
+ "UP", # pyupgrade
13
+ "ARG", # flake8-unused-arguments
14
+ "SIM", # flake8-simplify
15
+ "TCH", # flake8-type-checking
16
+ "PTH", # flake8-use-pathlib
17
+ "ERA", # eradicate
18
+ "PL", # pylint
19
+ "RUF", # ruff-specific rules
20
+ ]
21
+ ignore = [
22
+ "E501", # line too long, handled by black
23
+ "B008", # do not perform function calls in argument defaults
24
+ "C901", # too complex
25
+ "PLR0913", # too many arguments
26
+ "PLR0912", # too many branches
27
+ "PLR0915", # too many statements
28
+ ]
29
+
30
+ [lint.per-file-ignores]
31
+ "tests/*" = ["ARG", "S101", "PLR2004"]
32
+ "examples/*" = ["T201", "S101"]
33
+
34
+ [lint.isort]
35
+ known-first-party = ["skdr_eval"]
36
+
37
+ [format]
38
+ quote-style = "double"
39
+ indent-style = "space"
40
+ skip-magic-trailing-comma = false
41
+ line-ending = "auto"
@@ -0,0 +1,41 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0] - 2025-01-12
9
+
10
+ ### Added
11
+ - Initial release of skdr-eval library
12
+ - Core implementation of Doubly Robust (DR) and Stabilized Doubly Robust (SNDR) estimators
13
+ - Time-aware cross-validation with proper timestamp sorting for offline policy evaluation
14
+ - Synthetic data generation for testing and evaluation (`make_synth_logs`)
15
+ - Design matrix construction with context and action features (`build_design`)
16
+ - Propensity score fitting with time-aware calibration (`fit_propensity_timecal`)
17
+ - Outcome model fitting with cross-validation (`fit_outcome_crossfit`)
18
+ - Policy induction from sklearn models (`induce_policy_from_sklearn`)
19
+ - Bootstrap confidence intervals with moving-block bootstrap for time-series data
20
+ - Comprehensive evaluation function for sklearn models (`evaluate_sklearn_models`)
21
+ - Complete test suite with 17 tests covering all major functionality
22
+ - CI/CD workflows for automated testing and building
23
+ - Comprehensive documentation with examples and API reference
24
+ - Quickstart example demonstrating full evaluation workflow
25
+
26
+ ### Features
27
+ - 🎯 **Doubly Robust Estimation**: Implements both DR and Stabilized DR (SNDR) estimators
28
+ - ⏰ **Time-Aware Evaluation**: Uses time-series splits and calibrated propensity scores
29
+ - 🔧 **Sklearn Integration**: Easy integration with scikit-learn models
30
+ - 📊 **Comprehensive Diagnostics**: ESS, match rates, propensity score analysis
31
+ - 🚀 **Production Ready**: Type-hinted, tested, and documented
32
+ - 📈 **Bootstrap Confidence Intervals**: Moving-block bootstrap for time-series data
33
+
34
+ ### Technical Details
35
+ - Supports Python 3.9+
36
+ - Dependencies: numpy, pandas, scikit-learn>=1.1
37
+ - Full type hints and comprehensive error handling
38
+ - 74% test coverage
39
+ - Follows modern Python packaging standards
40
+
41
+ [0.1.0]: https://github.com/dandrsantos/skdr-eval/releases/tag/v0.1.0
@@ -0,0 +1,24 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use this software, please cite it as below."
3
+ type: software
4
+ title: "skdr-eval: Offline Policy Evaluation for Service-Time Minimization"
5
+ version: "0.1.0"
6
+ date-released: "2024-08-12"
7
+ url: "https://github.com/dandrsantos/skdr-eval"
8
+ repository-code: "https://github.com/dandrsantos/skdr-eval"
9
+ license: MIT
10
+ authors:
11
+ - family-names: "Santos"
12
+ given-names: "Diogo"
13
+ email: "diogofcul@gmail.com"
14
+ orcid: "https://orcid.org/0000-0000-0000-0000"
15
+ keywords:
16
+ - "offline evaluation"
17
+ - "doubly robust"
18
+ - "bandits"
19
+ - "causal inference"
20
+ - "policy evaluation"
21
+ abstract: >-
22
+ A Python library for offline policy evaluation using Doubly Robust (DR) and
23
+ Stabilized Doubly Robust (SNDR) estimators with time-aware splits and calibration
24
+ for service-time minimization problems.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Diogo Santos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.