facedyn 1.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.
- facedyn-1.1.0/.git-blame-ignore-revs +1 -0
- facedyn-1.1.0/.github/dependabot.yml +11 -0
- facedyn-1.1.0/.github/workflows/ci.yml +118 -0
- facedyn-1.1.0/.gitignore +67 -0
- facedyn-1.1.0/.pre-commit-config.yaml +32 -0
- facedyn-1.1.0/CHANGELOG.md +92 -0
- facedyn-1.1.0/CITATION.cff +51 -0
- facedyn-1.1.0/CONTRIBUTING.md +68 -0
- facedyn-1.1.0/LICENSE +21 -0
- facedyn-1.1.0/PKG-INFO +186 -0
- facedyn-1.1.0/README.md +149 -0
- facedyn-1.1.0/examples/01_data_preparation_and_splitting.ipynb +1573 -0
- facedyn-1.1.0/examples/02_nmf_facial_synergies.ipynb +1113 -0
- facedyn-1.1.0/examples/03_classification_and_interpretation.ipynb +1941 -0
- facedyn-1.1.0/examples/04_evaluation_pitfalls.ipynb +1242 -0
- facedyn-1.1.0/examples/05_reporting_checklist.ipynb +583 -0
- facedyn-1.1.0/examples/README.md +52 -0
- facedyn-1.1.0/examples/_nb_utils.py +137 -0
- facedyn-1.1.0/examples/bootstrap.py +179 -0
- facedyn-1.1.0/examples/environment.yml +24 -0
- facedyn-1.1.0/examples/helpers.py +64 -0
- facedyn-1.1.0/examples/run_cv.py +307 -0
- facedyn-1.1.0/examples/settings.py +29 -0
- facedyn-1.1.0/pyproject.toml +158 -0
- facedyn-1.1.0/src/facedyn/__init__.py +186 -0
- facedyn-1.1.0/src/facedyn/_plot_utils.py +21 -0
- facedyn-1.1.0/src/facedyn/au_labels.py +142 -0
- facedyn-1.1.0/src/facedyn/classifiers.py +277 -0
- facedyn-1.1.0/src/facedyn/crossval.py +685 -0
- facedyn-1.1.0/src/facedyn/effects.py +640 -0
- facedyn-1.1.0/src/facedyn/evaluation.py +1381 -0
- facedyn-1.1.0/src/facedyn/face_maps.py +723 -0
- facedyn-1.1.0/src/facedyn/feature_selection.py +1364 -0
- facedyn-1.1.0/src/facedyn/features/__init__.py +48 -0
- facedyn-1.1.0/src/facedyn/features/_utils.py +18 -0
- facedyn-1.1.0/src/facedyn/features/cleaning.py +359 -0
- facedyn-1.1.0/src/facedyn/features/external.py +334 -0
- facedyn-1.1.0/src/facedyn/features/reshape.py +252 -0
- facedyn-1.1.0/src/facedyn/features/timeseries.py +536 -0
- facedyn-1.1.0/src/facedyn/nmf.py +1149 -0
- facedyn-1.1.0/src/facedyn/normalisation.py +72 -0
- facedyn-1.1.0/src/facedyn/representative_aus.py +112 -0
- facedyn-1.1.0/src/facedyn/smoothing.py +208 -0
- facedyn-1.1.0/src/facedyn/splitting.py +767 -0
- facedyn-1.1.0/src/facedyn/tuning.py +723 -0
- facedyn-1.1.0/tests/conftest.py +91 -0
- facedyn-1.1.0/tests/unit/test_au_labels.py +31 -0
- facedyn-1.1.0/tests/unit/test_classifiers.py +175 -0
- facedyn-1.1.0/tests/unit/test_crossval.py +616 -0
- facedyn-1.1.0/tests/unit/test_effects.py +383 -0
- facedyn-1.1.0/tests/unit/test_evaluation.py +729 -0
- facedyn-1.1.0/tests/unit/test_external.py +182 -0
- facedyn-1.1.0/tests/unit/test_face_maps.py +285 -0
- facedyn-1.1.0/tests/unit/test_feature_cleaning.py +203 -0
- facedyn-1.1.0/tests/unit/test_feature_selection.py +940 -0
- facedyn-1.1.0/tests/unit/test_nmf.py +629 -0
- facedyn-1.1.0/tests/unit/test_normalisation.py +104 -0
- facedyn-1.1.0/tests/unit/test_pipeline_end_to_end.py +253 -0
- facedyn-1.1.0/tests/unit/test_representative_aus.py +151 -0
- facedyn-1.1.0/tests/unit/test_reshape.py +237 -0
- facedyn-1.1.0/tests/unit/test_smoothing.py +159 -0
- facedyn-1.1.0/tests/unit/test_splitting.py +588 -0
- facedyn-1.1.0/tests/unit/test_timeseries_features.py +389 -0
- facedyn-1.1.0/tests/unit/test_tuning.py +547 -0
- facedyn-1.1.0/tests/validation/fixtures/cmfts_input_subset.csv +11 -0
- facedyn-1.1.0/tests/validation/fixtures/cmfts_output_imputed_subset.csv +21 -0
- facedyn-1.1.0/tests/validation/fixtures/cmfts_output_imputed_zerosd_subset.csv +21 -0
- facedyn-1.1.0/tests/validation/fixtures/cmfts_output_subset.csv +11 -0
- facedyn-1.1.0/tests/validation/fixtures/nmf_basis_d.csv +4 -0
- facedyn-1.1.0/tests/validation/fixtures/nmf_basis_w.csv +18 -0
- facedyn-1.1.0/tests/validation/fixtures/nmf_reconstruction_h_subset.csv +301 -0
- facedyn-1.1.0/tests/validation/fixtures/nmf_reconstruction_input_subset.csv +301 -0
- facedyn-1.1.0/tests/validation/fixtures/normalisation_train_params.csv +18 -0
- facedyn-1.1.0/tests/validation/fixtures/r_normalised_subset.csv +3616 -0
- facedyn-1.1.0/tests/validation/fixtures/r_smoothed_20__exit_phone_room.csv +242 -0
- facedyn-1.1.0/tests/validation/fixtures/r_test_set_predictions.csv +95 -0
- facedyn-1.1.0/tests/validation/fixtures/raw_20__exit_phone_room.csv +242 -0
- facedyn-1.1.0/tests/validation/fixtures/raw_smoothed_normalisation_subset.csv +3616 -0
- facedyn-1.1.0/tests/validation/test_boruta_r_validation.py +269 -0
- facedyn-1.1.0/tests/validation/test_classifier_metrics_validation.py +280 -0
- facedyn-1.1.0/tests/validation/test_classifier_r_validation.py +204 -0
- facedyn-1.1.0/tests/validation/test_cmfts_r_bridge_validation.py +173 -0
- facedyn-1.1.0/tests/validation/test_feature_cleaning_r_validation.py +171 -0
- facedyn-1.1.0/tests/validation/test_nmf_decomposer_validation.py +145 -0
- facedyn-1.1.0/tests/validation/test_nmf_rank_cv_validation.py +57 -0
- facedyn-1.1.0/tests/validation/test_nmf_reconstruction_validation.py +162 -0
- facedyn-1.1.0/tests/validation/test_normalisation_validation.py +64 -0
- facedyn-1.1.0/tests/validation/test_representative_au_selection_validation.py +62 -0
- facedyn-1.1.0/tests/validation/test_smoothing_validation.py +34 -0
- facedyn-1.1.0/tests/validation/test_splitting_validation.py +38 -0
- facedyn-1.1.0/tools/rf_importance_vs_boruta.py +197 -0
- facedyn-1.1.0/tools/tune_threshold_paper1.py +197 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
98a205c2988a1c17050e2aae60d48154ff7f6877
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
# A new push to the same branch or PR cancels the run it replaces.
|
|
10
|
+
concurrency:
|
|
11
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
12
|
+
cancel-in-progress: true
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
lint:
|
|
16
|
+
name: Lint (pre-commit + mypy)
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v7
|
|
20
|
+
|
|
21
|
+
- uses: actions/setup-python@v7
|
|
22
|
+
with:
|
|
23
|
+
python-version: "3.12"
|
|
24
|
+
cache: pip
|
|
25
|
+
|
|
26
|
+
- name: Ruff lint, ruff format and file hygiene
|
|
27
|
+
uses: pre-commit/action@v3.0.1
|
|
28
|
+
|
|
29
|
+
- name: Install facedyn with the lint tools
|
|
30
|
+
run: |
|
|
31
|
+
python -m pip install --upgrade pip # dependency groups need pip >= 25.1
|
|
32
|
+
pip install --group lint -e .
|
|
33
|
+
|
|
34
|
+
- name: Type-check
|
|
35
|
+
run: mypy
|
|
36
|
+
|
|
37
|
+
test:
|
|
38
|
+
name: Test (Python ${{ matrix.python-version }})
|
|
39
|
+
runs-on: ubuntu-latest
|
|
40
|
+
strategy:
|
|
41
|
+
fail-fast: false
|
|
42
|
+
matrix:
|
|
43
|
+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
|
|
44
|
+
steps:
|
|
45
|
+
- uses: actions/checkout@v7
|
|
46
|
+
|
|
47
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
48
|
+
uses: actions/setup-python@v7
|
|
49
|
+
with:
|
|
50
|
+
python-version: ${{ matrix.python-version }}
|
|
51
|
+
allow-prereleases: true
|
|
52
|
+
cache: pip
|
|
53
|
+
|
|
54
|
+
- name: Install facedyn (test group + viz extra)
|
|
55
|
+
run: |
|
|
56
|
+
python -m pip install --upgrade pip # dependency groups need pip >= 25.1
|
|
57
|
+
pip install --group test -e ".[viz]"
|
|
58
|
+
|
|
59
|
+
- name: Run tests
|
|
60
|
+
# --runslow is required: `pytest` alone skips the expensive tests
|
|
61
|
+
# (Boruta fits, imputation, rpy2) so the local edit loop stays in
|
|
62
|
+
# seconds. CI is where they have to run.
|
|
63
|
+
run: pytest --runslow
|
|
64
|
+
|
|
65
|
+
core-import:
|
|
66
|
+
name: Core import (no optional extras)
|
|
67
|
+
runs-on: ubuntu-latest
|
|
68
|
+
steps:
|
|
69
|
+
- uses: actions/checkout@v7
|
|
70
|
+
|
|
71
|
+
- name: Set up Python
|
|
72
|
+
uses: actions/setup-python@v7
|
|
73
|
+
with:
|
|
74
|
+
python-version: "3.12"
|
|
75
|
+
cache: pip
|
|
76
|
+
|
|
77
|
+
- name: Install facedyn (no extras)
|
|
78
|
+
run: pip install -e .
|
|
79
|
+
|
|
80
|
+
- name: Import every submodule without matplotlib or rpy2 installed
|
|
81
|
+
# Walks the package, so a new module is checked without editing this.
|
|
82
|
+
run: |
|
|
83
|
+
python -c "
|
|
84
|
+
import importlib, pkgutil, facedyn
|
|
85
|
+
names = [m.name for m in pkgutil.walk_packages(facedyn.__path__, 'facedyn.')]
|
|
86
|
+
for name in names:
|
|
87
|
+
importlib.import_module(name)
|
|
88
|
+
print(f'facedyn {facedyn.__version__}: {len(names)} modules import with no optional dependencies')
|
|
89
|
+
"
|
|
90
|
+
|
|
91
|
+
build:
|
|
92
|
+
name: Build and check the distribution
|
|
93
|
+
runs-on: ubuntu-latest
|
|
94
|
+
steps:
|
|
95
|
+
- uses: actions/checkout@v7
|
|
96
|
+
|
|
97
|
+
- uses: actions/setup-python@v7
|
|
98
|
+
with:
|
|
99
|
+
python-version: "3.12"
|
|
100
|
+
|
|
101
|
+
- name: Build sdist and wheel
|
|
102
|
+
run: pipx run build
|
|
103
|
+
|
|
104
|
+
- name: Check metadata renders on PyPI
|
|
105
|
+
run: pipx run twine check --strict dist/*
|
|
106
|
+
|
|
107
|
+
# The one check to mark as required in branch protection: it fails if any
|
|
108
|
+
# job above failed or was cancelled, so adding a job never needs a
|
|
109
|
+
# settings change.
|
|
110
|
+
pass:
|
|
111
|
+
name: All checks passed
|
|
112
|
+
if: always()
|
|
113
|
+
needs: [lint, test, core-import, build]
|
|
114
|
+
runs-on: ubuntu-latest
|
|
115
|
+
steps:
|
|
116
|
+
- uses: re-actors/alls-green@release/v1
|
|
117
|
+
with:
|
|
118
|
+
jobs: ${{ toJSON(needs) }}
|
facedyn-1.1.0/.gitignore
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# OS
|
|
2
|
+
.DS_Store
|
|
3
|
+
|
|
4
|
+
# Python
|
|
5
|
+
__pycache__/
|
|
6
|
+
*.py[cod]
|
|
7
|
+
*.egg-info/
|
|
8
|
+
.eggs/
|
|
9
|
+
build/
|
|
10
|
+
dist/
|
|
11
|
+
|
|
12
|
+
# Test / tool caches
|
|
13
|
+
.pytest_cache/
|
|
14
|
+
.mypy_cache/
|
|
15
|
+
.ruff_cache/
|
|
16
|
+
.coverage
|
|
17
|
+
htmlcov/
|
|
18
|
+
.claude/
|
|
19
|
+
|
|
20
|
+
# Virtual environments
|
|
21
|
+
.venv/
|
|
22
|
+
venv/
|
|
23
|
+
env/
|
|
24
|
+
|
|
25
|
+
# Editors
|
|
26
|
+
.vscode/
|
|
27
|
+
.idea/
|
|
28
|
+
|
|
29
|
+
# Outdated code, not relevant to facedyn
|
|
30
|
+
cmfts_port/
|
|
31
|
+
|
|
32
|
+
# Data for validation/testing
|
|
33
|
+
Data/
|
|
34
|
+
python_smoothed.csv
|
|
35
|
+
R Validation Data/
|
|
36
|
+
|
|
37
|
+
# Notes (more for me than anything)
|
|
38
|
+
PIPELINE.md
|
|
39
|
+
PROJECT_STRUCTURE.md
|
|
40
|
+
DATA_FORMAT.md
|
|
41
|
+
ROADMAP_v1.1.md
|
|
42
|
+
PACKAGE_BEST_PRACTICES.md
|
|
43
|
+
EXTERNAL_FILE_*
|
|
44
|
+
|
|
45
|
+
# R code - this is mainly for testing the new version of RccpML
|
|
46
|
+
# which released a new version with rank selection stuff after I last used it.
|
|
47
|
+
r_rank_selection/
|
|
48
|
+
|
|
49
|
+
# Threshold-tuning run outputs (derived from the gitignored R data above)
|
|
50
|
+
tools/threshold_tuning/
|
|
51
|
+
|
|
52
|
+
# Diagnosis scripts
|
|
53
|
+
# Mainly to debug python stuff
|
|
54
|
+
diagnose*
|
|
55
|
+
diagnose.py
|
|
56
|
+
face_maps_*
|
|
57
|
+
smoothing_diagnostic.png
|
|
58
|
+
|
|
59
|
+
# Other
|
|
60
|
+
_*/
|
|
61
|
+
|
|
62
|
+
# Local outputs/data generated when running tutorial notebooks in examples/
|
|
63
|
+
examples/outputs/
|
|
64
|
+
examples/data/
|
|
65
|
+
examples/cache/
|
|
66
|
+
examples/results/
|
|
67
|
+
examples/figures/
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Run on every commit after `pre-commit install`; run on everything with
|
|
2
|
+
# `pre-commit run --all-files`. Hooks that modify files come before hooks
|
|
3
|
+
# that only check. Bump the pinned revisions with `pre-commit autoupdate`.
|
|
4
|
+
# The R-validation fixtures stay byte-for-byte; tutorial notebooks in examples/
|
|
5
|
+
# embed rendered output figures (>1 MB) and are kept verbatim.
|
|
6
|
+
exclude: ^(tests/validation/fixtures/|examples/)
|
|
7
|
+
|
|
8
|
+
repos:
|
|
9
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
10
|
+
rev: v5.0.0
|
|
11
|
+
hooks:
|
|
12
|
+
- id: trailing-whitespace
|
|
13
|
+
- id: end-of-file-fixer
|
|
14
|
+
- id: mixed-line-ending
|
|
15
|
+
- id: check-yaml
|
|
16
|
+
- id: check-toml
|
|
17
|
+
- id: check-merge-conflict
|
|
18
|
+
- id: check-added-large-files
|
|
19
|
+
args: ["--maxkb=1000"]
|
|
20
|
+
- id: debug-statements
|
|
21
|
+
- id: name-tests-test
|
|
22
|
+
args: ["--pytest-test-first"]
|
|
23
|
+
# conftest.py is pytest configuration, not a test module.
|
|
24
|
+
exclude: ^tests/conftest\.py$
|
|
25
|
+
|
|
26
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
27
|
+
# Keep in step with the ruff version in the `lint` dependency group.
|
|
28
|
+
rev: v0.9.6
|
|
29
|
+
hooks:
|
|
30
|
+
- id: ruff
|
|
31
|
+
args: ["--fix", "--show-fixes"]
|
|
32
|
+
- id: ruff-format
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to facedyn will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [1.1.0] - 2026-12-02
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Top-level package re-exports for smoothing and NMF diagnostics (`plot_smoothing_comparison`, `nmf_reconstruction_error`, `nmf_reconstruction_r2_per_au`, `plot_nmf_basis_heatmap`, `plot_nmf_cophenetic_correlation`, `plot_nmf_rank_cv`, `plot_nmf_reconstruction`, `plot_nmf_reconstruction_extremes`, `plot_nmf_reconstruction_r2_bar`), matching the main API summary in the accompanying methodology article.
|
|
14
|
+
- Five-part worked-example tutorial notebook series and user guide in `examples/`, plus `CITATION.cff` citation metadata for GitHub and Zenodo.
|
|
15
|
+
|
|
16
|
+
- Participant-level grouping for repeated-measures data, where the participant (not the video) is the unit of independence and sessions nest within participant:
|
|
17
|
+
- `group_train_test_split(..., group_col=None)`: pass e.g. `group_col="participant"` to keep all of a participant's videos on one side of the split. `train_size` is then a fraction of participants. The default (`None`) behaves exactly as before.
|
|
18
|
+
- `groups_from_column(df, group_col, video_col, videos=None)`: builds the `groups` array for `RepeatedStratifiedGroupKFold` / `cross_validate_grouped` from an id column, optionally aligned to a given video order (e.g. a `pivot_features_wide` table).
|
|
19
|
+
- `group_report(df, group_col, video_col, label_col=None)`: videos per group and, with `label_col`, class counts per group.
|
|
20
|
+
- All three raise if a video has a missing group id or more than one.
|
|
21
|
+
|
|
22
|
+
- `cross_validate_pipeline(frames, labels, groups, ...)` (new module `facedyn.crossval`): grouped cross-validation from frame-level data that refits every fitted step inside each fold (normaliser, NMF, representative-AU choice, feature extraction, cleaner, feature selector and classifier), so nothing fitted ever sees a test-fold video. Smoothing runs once up front, since it is per-video and learns nothing. Each step takes `None` (default), your own unfitted estimator, or `False` to skip it; `representative_aus=False` uses NMF activations instead. Works with two or more classes, and folds run in parallel with `n_jobs`.
|
|
23
|
+
- `CVPipelineResult`: `oof` (out-of-fold predictions for every video in every repeat, with one `proba_<class>` column per class), `scores` (per fold), `selected_aus` and `selected_features` (per fold, with Boruta's per-fold `selection_freq`), optional `nmf_bases` (`keep_bases=True`) and fitted fold models (`keep_models=True`); plus `.summary()`, `.au_frequency()`, `.feature_frequency()` and `.oof_metrics()` (pooled out-of-fold ROC-AUC per repeat, with a DeLong CI for binary labels).
|
|
24
|
+
- Multiclass evaluation:
|
|
25
|
+
- `classification_metrics` handles more than two classes. It reports accuracy and its exact CI, the no-information rate, kappa, MCC, balanced accuracy, macro F1 and macro one-vs-rest ROC-AUC. It also gives each class `c` its own `precision_c`, `recall_c`, `f1_c` and `roc_auc_c`, the last with a DeLong CI. Pass `y_score` as a 2-D probability array, with the new `labels=` argument giving its column order.
|
|
26
|
+
- A binary `y_score` may also be 2-D now. The binary path is otherwise unchanged; the R-validation tests still pass.
|
|
27
|
+
- `evaluate_models` scores models with more than two classes using the multiclass statistics.
|
|
28
|
+
- `plot_roc_curves` draws one one-vs-rest curve per class for multiclass models.
|
|
29
|
+
- New `plot_roc_ovr(y_true, y_score, labels)` does the same from probabilities alone, e.g. pooled out-of-fold predictions.
|
|
30
|
+
- `plot_confusion_matrix` takes `normalize="reference"` (each true class sums to 1, so recall is on the diagonal) or `"prediction"` (the same as `True`). It also takes `annotate="count" | "proportion" | "both"`. Normalised shading now runs over a fixed 0–1 range, and a row or column with no entries shades as 0 rather than NaN.
|
|
31
|
+
- New `pairwise_contrasts(data, label_col, pairs=None)` returns the binary subsets (e.g. happy–sad, happy–angry, sad–angry) for pairwise DeLong tests, since DeLong itself stays binary.
|
|
32
|
+
- `CVPipelineResult.oof_metrics()` adds a one-vs-rest `roc_auc_<class>` for each class when there are more than two.
|
|
33
|
+
|
|
34
|
+
- Feature effects with accumulated local effects (new module `facedyn.effects`). ALE is used instead of partial dependence because facedyn's time-series features are strongly correlated (Apley & Zhu, 2020). It is implemented from the paper's definition, with no `ALEPlot`/`alibi`/`PyALE` code or dependency.
|
|
35
|
+
- `feature_effect_ale(model, X, features, grid_size=20, classes=None, grid=None)`: centred first-order ALE on an empirical-quantile grid. Classifiers give one probability curve per class (the positive class only for binary models); other models use `predict`. Returns a long table with `feature`, `class`, `value`, `effect`, `n`.
|
|
36
|
+
- `feature_effect_ale_cv(result, features, X=None, ...)`: the same for every fold model of a `cross_validate_pipeline(..., keep_models=True)` run, on one grid shared by all folds. Each fold is estimated over its own test videos by default. Folds whose selector dropped the feature are left out, so compare with `feature_frequency()`.
|
|
37
|
+
- `summarise_feature_effects(curves)`: mean, SD, min and max across folds at each grid value, plus `n_folds`.
|
|
38
|
+
- `plot_feature_effect(model_or_result, X=None, features=None, ...)`: one panel per feature with a rug of the data. For a CV result it draws the mean curve with an SD or min-max band (and optionally each fold's curve), and the title says in how many folds the feature was used.
|
|
39
|
+
- `ale_grid(values, grid_size)`: the interval edges used.
|
|
40
|
+
- `humanise_feature_label("kurtosis_smth_AU12_r")` gives `"AU12 - Lip Corner Puller — kurtosis"`.
|
|
41
|
+
|
|
42
|
+
- `facedyn.__version__`. The version is now defined once, in `src/facedyn/__init__.py`, and read from there by the build.
|
|
43
|
+
- Every public module defines `__all__`.
|
|
44
|
+
- README section "Input data" describing the expected frame-level shape. Docstrings point to it.
|
|
45
|
+
- `CONTRIBUTING.md`: setup, checks, coding conventions and the release steps.
|
|
46
|
+
- Development tooling, following the Scientific Python Development Guide:
|
|
47
|
+
- ruff (lint and format) and mypy, configured in `pyproject.toml` and run through pre-commit (`.pre-commit-config.yaml`).
|
|
48
|
+
- Development dependencies are now dependency groups (`test`, `lint`, `dev`): `pip install --group dev -e .`. The `dev` extra is removed.
|
|
49
|
+
- Stricter pytest configuration: `--strict-markers`, `--strict-config`, `xfail_strict`, and warnings raised as errors.
|
|
50
|
+
- CI: a lint and type-check job, a build-and-`twine check` job, Python 3.14 in the test matrix, cancellation of superseded runs, an automatic import check over every submodule, and one "All checks passed" job to require. Dependabot keeps the action versions current.
|
|
51
|
+
|
|
52
|
+
### Changed
|
|
53
|
+
|
|
54
|
+
- `oob_permutation_importance` (the default Boruta importance) is faster and returns exactly the same values for a given `random_state`. Each tree now makes one `predict` call on a stacked block of permuted copies, instead of one call per column, and skips columns the tree never splits on (their drop is exactly 0 either way). One importance call on 185 rows × 180 columns fell from 3.6 s to 0.7 s, most of what is left being the forest fit. On a real cross-validation fold with single-run Boruta, the whole fold fell from 204 s to 149 s. A new test checks that the result matches the old loop exactly.
|
|
55
|
+
- `"svm_rbf"` is now `CalibratedClassifierCV(SVC(kernel="rbf"), method="sigmoid", cv=5, ensemble=False)` instead of `SVC(probability=True)`, which scikit-learn 1.9 deprecates (removal in 1.11). Both do Platt scaling on 5-fold cross-validated decision values; the wrapper is used on every scikit-learn version so results do not depend on the installed one. SVM probabilities will differ slightly from 1.0.0. `predict` now always agrees with `predict_proba`. The SVC's own parameters move one level down: `estimator__C` in `make_classifier` overrides and `PAPER1_PARAMS`, `classifier__estimator__C` in `PAPER1_PARAM_GRIDS`. The SVM is deterministic and ignores `random_state`.
|
|
56
|
+
- `classification_metrics` and `evaluate_models` now raise if `positive_label` is given with more than two classes. Previously they quietly computed one-vs-rest binary statistics. Use the per-class columns or `pairwise_contrasts` instead.
|
|
57
|
+
- `threshold_sweep` and `tune_selection_threshold` raise a clear error for `scoring="roc_auc"` with more than two classes, because DeLong is binary. The tuner raises before any Boruta fit. The error points to `scoring="roc_auc_ovr"`.
|
|
58
|
+
- `plot_smoothing_comparison(..., mode="overlay")` now draws the raw trajectory as a thin crisp solid line on top of a thicker semi-transparent solid smoothed line, keeping high-frequency jitter sharp and both curves clearly distinguishable even under short smoothing windows.
|
|
59
|
+
- `plot_nmf_basis_heatmap(..., mark_representative=True)` now marks each component's highest-loading (representative) AU with a star marker by default (set `mark_representative=False` to omit).
|
|
60
|
+
- `plot_probability_distributions` and `plot_decision_boundary` label the negative group "rest" when it contains more than one class.
|
|
61
|
+
- `cross_validate_grouped`'s docstring now says it is for feature tables nothing has been fitted to, and points to `cross_validate_pipeline` otherwise.
|
|
62
|
+
- The missing-`groups` messages from `RepeatedStratifiedGroupKFold` and `cross_validate_grouped` now point to `groups_from_column` as well as `pair_groups`.
|
|
63
|
+
- General-purpose framing. facedyn is now described as a tool for classifying AU time series in general. Deepfake detection is one documented application; it is no longer the package's scope.
|
|
64
|
+
- `pyproject.toml`: new description ("Interpretable, leakage-aware classification of facial action unit time series."), plus keywords, trove classifiers and `project.urls` (Homepage, Documentation, Issues, Changelog).
|
|
65
|
+
- README: rewritten around repeated-measures and matched-pairs designs. The emotion and deepfake studies are listed as two applications. The quickstart uses participant grouping, `cross_validate_pipeline`, the multiclass plots and ALE.
|
|
66
|
+
- The package has a module docstring. It says once that "the original R analysis" and "the deepfake study" refer to Murphy, Cook & Cuve (in prep).
|
|
67
|
+
- Docstrings and messages no longer mention "Paper 1". They speak of classes or labels rather than real/fake, except for the matched-pairs helpers, whose real/fake defaults are kept and documented as the deepfake case.
|
|
68
|
+
- `cross_validate_grouped`'s missing-`groups` warning is generic: it says splitting repeated measures or matched pairs can inflate or deflate a score. The `positive_label` and `tune_selection_threshold` errors no longer cite one study's choices.
|
|
69
|
+
- `paired_train_test_split`'s broken-pairing error says "source video" instead of "real video".
|
|
70
|
+
- No change to the API, defaults or behaviour. `make_classifier`'s default `preset="paper1"` stays as it is, so existing code still reproduces the published numbers.
|
|
71
|
+
|
|
72
|
+
### Fixed
|
|
73
|
+
|
|
74
|
+
- `plot_nmf_rank_cv(robust=True)`: the bold summary line is now clipped to the robust axis range like the individual replicates, and the y-axis starts at 0. Previously, when most replicates at a rank were degenerate (so the median was too), the unclipped line pushed the lower axis limit far below zero and flattened the real curve.
|
|
75
|
+
- Feature extraction now works on videos of different lengths. `reshape_to_wide` pads shorter videos with trailing NaNs up to the longest video, and every extractor then rejected them ("Series contains N NaN value(s)"), so `cross_validate_pipeline` failed on any dataset with unequal video lengths. `apply_rowwise`, which all extractors share, now drops trailing padding before computing features. A gap *inside* a series is still passed through and still rejected.
|
|
76
|
+
- Every transformer listed `BaseEstimator` before `TransformerMixin`. On scikit-learn 1.6 or later that made them report that they were not transformers (`__sklearn_tags__().transformer_tags` was `None`). They now list the mixin first, as scikit-learn requires.
|
|
77
|
+
- Lists that must be the same length are zipped with `strict=True`, so a mismatch raises instead of silently dropping items.
|
|
78
|
+
- Docstrings no longer refer to development notes that are not in the repository.
|
|
79
|
+
|
|
80
|
+
## [1.0.0]
|
|
81
|
+
|
|
82
|
+
Initial release. Covers the full pipeline from Murphy, Cook, & Cuve (in prep): smoothing, train/test splitting, z-score normalisation, NMF decomposition and rank selection, feature extraction and selection (including a Boruta implementation), classification, evaluation, and threshold tuning.
|
|
83
|
+
|
|
84
|
+
### Added
|
|
85
|
+
|
|
86
|
+
- `plot_nmf_face_maps(..., full_range=False)`: opt in with `full_range=True` to shade regions using the colormap's full `[0, 1]` range instead of py-feat's capped-at-67% quantised palette, so color intensity matches `plot_nmf_basis_heatmap` for the same underlying value. Default behaviour (py-feat-faithful rendering) is unchanged.
|
|
87
|
+
- `plot_nmf_reconstruction(..., au_label=None)` and `plot_nmf_reconstruction_extremes(..., humanise=False)`: caption plots with a humanised AU name (e.g. `"AU07 - Lid Tightener"`) instead of the raw column name, without affecting which column is plotted.
|
|
88
|
+
|
|
89
|
+
### Fixed
|
|
90
|
+
|
|
91
|
+
- `plot_nmf_face_maps(..., normalize=False)` raised `ValueError: alpha (...) is outside 0-1 range` whenever a raw (unnormalized) component value exceeded 1 — the alpha calculation assumed values were already bounded to `[0, 1]`, which only holds after normalization. Values are now clipped to `[0, 1]` before use, matching the behaviour the docstring already claimed ("saturate every region to the same colour").
|
|
92
|
+
- `plot_nmf_reconstruction_extremes`'s titles (AU name + "Original vs. Reconstructed" + video ID) overlapped into an unreadable jumble for longer video filenames. Titles now split across two lines and use `wrap=True` to further wrap anything still too long, and the default figure is wider (`(11, 4.5)` instead of `(9, 4)`).
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
title: "facedyn: Interpretable, leakage-aware classification of facial Action Unit dynamics"
|
|
3
|
+
message: "If you use facedyn in your research, please cite both the software release and the accompanying methodology article."
|
|
4
|
+
type: software
|
|
5
|
+
version: "1.1.0"
|
|
6
|
+
date-released: "2026-12-02"
|
|
7
|
+
license: MIT
|
|
8
|
+
repository-code: "https://github.com/tj-murphy/facedyn"
|
|
9
|
+
url: "https://github.com/tj-murphy/facedyn"
|
|
10
|
+
abstract: >-
|
|
11
|
+
An open-source Python package for interpretable, leakage-aware classification
|
|
12
|
+
of facial Action Unit (AU) time series. Built on scikit-learn, facedyn
|
|
13
|
+
enforces grouped splitting and fold-internal refitting across normalisation,
|
|
14
|
+
non-negative matrix factorisation (NMF), optional representative AU selection,
|
|
15
|
+
31 named time series features, repeated Boruta stability selection with
|
|
16
|
+
correlated feature clustering, and cross-validation averaged accumulated local
|
|
17
|
+
effects (ALE).
|
|
18
|
+
keywords:
|
|
19
|
+
- facial action units
|
|
20
|
+
- facial dynamics
|
|
21
|
+
- affective science
|
|
22
|
+
- artificial intelligence
|
|
23
|
+
- interpretable machine learning
|
|
24
|
+
- time series classification
|
|
25
|
+
- data leakage
|
|
26
|
+
- cross-validation
|
|
27
|
+
- OpenFace
|
|
28
|
+
authors:
|
|
29
|
+
- family-names: Murphy
|
|
30
|
+
given-names: Timothy Joseph
|
|
31
|
+
affiliation: "University of Birmingham; University of Bristol"
|
|
32
|
+
email: "tim.murphy@bristol.ac.uk"
|
|
33
|
+
- family-names: Cook
|
|
34
|
+
given-names: Jennifer
|
|
35
|
+
affiliation: "University of Birmingham"
|
|
36
|
+
- family-names: Cuve
|
|
37
|
+
given-names: Hélio Clemente José
|
|
38
|
+
affiliation: "University of Bristol"
|
|
39
|
+
preferred-citation:
|
|
40
|
+
type: article
|
|
41
|
+
title: "facedyn: Interpretable, Leakage-Aware Classification of Facial Action Unit Dynamics"
|
|
42
|
+
authors:
|
|
43
|
+
- family-names: Murphy
|
|
44
|
+
given-names: Timothy Joseph
|
|
45
|
+
- family-names: Cook
|
|
46
|
+
given-names: Jennifer
|
|
47
|
+
- family-names: Cuve
|
|
48
|
+
given-names: Hélio Clemente José
|
|
49
|
+
journal: "Affective Science"
|
|
50
|
+
year: 2026
|
|
51
|
+
notes: "Manuscript submitted for publication."
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Contributing to facedyn
|
|
2
|
+
|
|
3
|
+
Bug reports, questions and pull requests are welcome. Please open an
|
|
4
|
+
[issue](https://github.com/tj-murphy/facedyn/issues) first for anything
|
|
5
|
+
larger than a small fix, so we can agree on the approach.
|
|
6
|
+
|
|
7
|
+
## Reporting a bug
|
|
8
|
+
|
|
9
|
+
Include:
|
|
10
|
+
- the facedyn version (`python -c "import facedyn; print(facedyn.__version__)"`),
|
|
11
|
+
plus your Python, pandas and scikit-learn versions;
|
|
12
|
+
- a minimal example that reproduces the problem, ideally on synthetic data;
|
|
13
|
+
- what you expected and what happened, with the full traceback.
|
|
14
|
+
|
|
15
|
+
## Setting up
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
git clone https://github.com/tj-murphy/facedyn.git
|
|
19
|
+
cd facedyn
|
|
20
|
+
python -m pip install -U pip # dependency groups need pip >= 25.1
|
|
21
|
+
pip install --group dev -e ".[viz]" # tests, ruff, mypy, pre-commit
|
|
22
|
+
pre-commit install # lint and format on every commit
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
For the R bridge (`RFeatureExtractor`), also install the `r` extra and a
|
|
26
|
+
working R: `pip install -e ".[viz,r]"`. On R 4.4 or older, pin `rpy2<3.6`.
|
|
27
|
+
|
|
28
|
+
## Checks
|
|
29
|
+
|
|
30
|
+
| Command | What it does |
|
|
31
|
+
|---|---|
|
|
32
|
+
| `pytest` | Fast tests, about a minute. Tests marked `slow` are skipped. |
|
|
33
|
+
| `pytest --runslow` | Everything, including Boruta fits and the R-validation tests. CI runs this. |
|
|
34
|
+
| `pre-commit run --all-files` | Ruff lint and format, plus file hygiene. |
|
|
35
|
+
| `mypy` | Type-check `src/`. |
|
|
36
|
+
|
|
37
|
+
The test configuration treats warnings as errors. If your change makes
|
|
38
|
+
facedyn warn on purpose, assert it in the test with `pytest.warns`.
|
|
39
|
+
|
|
40
|
+
The suite leaves two cores free on machines with more than four, since
|
|
41
|
+
several tests ask for `n_jobs=-1`. Add `nice -n 19` for a full run you want
|
|
42
|
+
to forget about.
|
|
43
|
+
|
|
44
|
+
## Conventions
|
|
45
|
+
|
|
46
|
+
- **Code style**: ruff, configured in `pyproject.toml`. Line length 100.
|
|
47
|
+
- **Docstrings**: numpy style for every public function, class and method.
|
|
48
|
+
- **Estimators**: follow scikit-learn's rules. `__init__` only stores its
|
|
49
|
+
arguments; validation and fitting happen in `fit`; fitted attributes end
|
|
50
|
+
in `_`; randomness comes from a `random_state` argument; list the mixins
|
|
51
|
+
before `BaseEstimator` (`class X(TransformerMixin, BaseEstimator)`).
|
|
52
|
+
- **Exports**: add each new public name to its module's `__all__`, and to
|
|
53
|
+
`facedyn/__init__.py` if it belongs in the top-level API.
|
|
54
|
+
- **Tests**: every new function gets unit tests in `tests/unit/`. Mark
|
|
55
|
+
anything that takes more than a few seconds `@pytest.mark.slow`.
|
|
56
|
+
- **Validation against R**: tests in `tests/validation/` compare facedyn
|
|
57
|
+
with the original R analysis's output. A change that breaks one needs a
|
|
58
|
+
reason, not a new tolerance.
|
|
59
|
+
- **Licences**: implement methods from their published description and cite
|
|
60
|
+
it in the docstring. Do not copy code from GPL-licensed packages.
|
|
61
|
+
- **Changelog**: add a line under `[Unreleased]` in `CHANGELOG.md`.
|
|
62
|
+
|
|
63
|
+
## Releasing (maintainer)
|
|
64
|
+
|
|
65
|
+
1. Move the `[Unreleased]` entries in `CHANGELOG.md` under the new version.
|
|
66
|
+
2. Set `__version__` in `src/facedyn/__init__.py`.
|
|
67
|
+
3. Tag `vX.Y.Z` and publish a GitHub release. Zenodo archives the release
|
|
68
|
+
and mints a DOI (once the repository is connected to Zenodo).
|
facedyn-1.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Timothy Murphy
|
|
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.
|
facedyn-1.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: facedyn
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Interpretable, leakage-aware classification of facial action unit time series.
|
|
5
|
+
Project-URL: Homepage, https://github.com/tj-murphy/facedyn
|
|
6
|
+
Project-URL: Documentation, https://github.com/tj-murphy/facedyn#readme
|
|
7
|
+
Project-URL: Issues, https://github.com/tj-murphy/facedyn/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/tj-murphy/facedyn/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Timothy Murphy
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: OpenFace,affective computing,classification,cross-validation,facial action units,facial expression,feature selection,interpretability,time series
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: joblib>=1.2
|
|
27
|
+
Requires-Dist: numpy>=1.24
|
|
28
|
+
Requires-Dist: pandas>=2.0
|
|
29
|
+
Requires-Dist: scikit-learn>=1.3
|
|
30
|
+
Requires-Dist: scipy>=1.10
|
|
31
|
+
Requires-Dist: threadpoolctl>=3.1
|
|
32
|
+
Provides-Extra: r
|
|
33
|
+
Requires-Dist: rpy2>=3.5; extra == 'r'
|
|
34
|
+
Provides-Extra: viz
|
|
35
|
+
Requires-Dist: matplotlib>=3.7; extra == 'viz'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# facedyn
|
|
39
|
+
|
|
40
|
+
**Interpretable, leakage-aware classification of facial action unit (AU) time series.**
|
|
41
|
+
facedyn takes frame-level AU intensities (e.g. from OpenFace) and builds
|
|
42
|
+
video-level classifiers whose features can be read in terms of facial
|
|
43
|
+
movement. Every step that learns from data is fitted inside the training
|
|
44
|
+
folds, and splitting respects the unit of independence, so the scores you
|
|
45
|
+
report are not inflated by leakage.
|
|
46
|
+
|
|
47
|
+
It works with binary or multiclass labels and with any grouping structure:
|
|
48
|
+
- **Repeated measures**: several videos per participant, possibly across
|
|
49
|
+
sessions. The participant is the unit.
|
|
50
|
+
- **Matched pairs**: e.g. a real video and the deepfake made from it. The
|
|
51
|
+
pair is the unit.
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install facedyn # core
|
|
55
|
+
pip install facedyn[viz] # + matplotlib, for the plot_* functions
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Applications
|
|
59
|
+
|
|
60
|
+
- **Emotion expression** (happy / sad / angry, repeated measures with
|
|
61
|
+
participant grouping): the worked example in the accompanying methodology
|
|
62
|
+
article. Full walkthrough notebooks are in
|
|
63
|
+
[`examples/`](examples/).
|
|
64
|
+
- **Deepfake detection** (real / fake, matched pairs): Murphy, Cook & Cuve
|
|
65
|
+
(in prep). facedyn began as the Python port of this study's R analysis.
|
|
66
|
+
Regression tests still check the binary path against that analysis's
|
|
67
|
+
output, number for number.
|
|
68
|
+
|
|
69
|
+
## The pipeline
|
|
70
|
+
|
|
71
|
+
| Stage | What it does | Main API |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| **Smoothing** | Rolling mean per video, edge-extended, with overlay check | `RollingSmoother`, `plot_smoothing_comparison` |
|
|
74
|
+
| **Splitting** | Train/test and CV groups that keep a participant (or a matched pair) on one side | `group_train_test_split`, `groups_from_column`, `group_report`, `paired_train_test_split`, `pair_groups` |
|
|
75
|
+
| **Normalisation** | Z-score plus the non-negativity shift NMF needs | `ZScoreShiftNormalizer` |
|
|
76
|
+
| **Dimensionality reduction** | NMF, rank selection, basis heatmaps, face maps, and reconstruction diagnostics | `NMFDecomposer`, `nmf_rank_cv_sweep`, `nmf_cophenetic_correlation`, `nmf_reconstruction_r2_per_au`, `plot_nmf_basis_heatmap`, `plot_nmf_face_maps` |
|
|
77
|
+
| **Representative AUs** | Keep the top-loading AU per component | `RepresentativeAUSelector` |
|
|
78
|
+
| **Feature extraction** | 31 interpretable features per series, or bridge to another package | `TimeSeriesFeatureExtractor`, `RFeatureExtractor`, `CallableFeatureExtractor` |
|
|
79
|
+
| **Feature cleanup** | NaN/Inf/zero-variance report, then optional imputation | `feature_diagnostics`, `FeatureCleaner` |
|
|
80
|
+
| **Feature selection** | Native Boruta, repeated across seeds for stability | `BorutaSelector`, `correlated_feature_clusters` |
|
|
81
|
+
| **Threshold tuning** | Picks Boruta's stability threshold on data held out of training | `tune_selection_threshold` |
|
|
82
|
+
| **Classification** | Random forest, RBF SVM, logistic regression, C5.0 substitute; binary or multiclass | `make_classifiers`, `fit_classifiers` |
|
|
83
|
+
| **Cross-validation** | Refits every step above inside each fold; out-of-fold predictions and per-fold selections | `cross_validate_pipeline`, `cross_validate_grouped` |
|
|
84
|
+
| **Evaluation** | `caret`/`pROC`-equivalent statistics, macro one-vs-rest AUC, DeLong tests, figures | `classification_metrics`, `roc_auc_delong_ci`, `delong_roc_test`, `pairwise_contrasts`, `plot_roc_ovr`, `plot_confusion_matrix` |
|
|
85
|
+
| **Interpretation** | Accumulated local effects (ALE) per feature, averaged over CV folds | `plot_feature_effect`, `feature_effect_ale_cv` |
|
|
86
|
+
|
|
87
|
+
Every transformer follows the scikit-learn `fit`/`transform` contract, so
|
|
88
|
+
you can swap any stage for your own.
|
|
89
|
+
|
|
90
|
+
## Input data
|
|
91
|
+
|
|
92
|
+
facedyn reads long-format, frame-level data: one row per video frame.
|
|
93
|
+
|
|
94
|
+
| Column | Default name | Notes |
|
|
95
|
+
|---|---|---|
|
|
96
|
+
| Video id | `video_filename` | Groups the frames of one video. Every function that needs it takes `video_col`. |
|
|
97
|
+
| Frame number | `frame` | Orders frames within a video (`frame_col`). |
|
|
98
|
+
| AU intensities | any column ending `_r` (e.g. `AU01_r`) | OpenFace's naming. Override with `column_pattern=` or `columns=[...]`. |
|
|
99
|
+
| Label | any name | Constant within a video. Binary or multiclass. |
|
|
100
|
+
| Group | any name | The unit of independence, e.g. `participant`. Constant within a video. |
|
|
101
|
+
|
|
102
|
+
| video_filename | frame | participant | emotion | AU01_r | AU06_r | AU12_r |
|
|
103
|
+
|---|---|---|---|---|---|---|
|
|
104
|
+
| p01_happy_1 | 1 | p01 | happy | 0.4 | 0.1 | 0.0 |
|
|
105
|
+
| p01_happy_1 | 2 | p01 | happy | 0.5 | 0.2 | 0.1 |
|
|
106
|
+
| p02_sad_1 | 1 | p02 | sad | 0.0 | 0.3 | 0.6 |
|
|
107
|
+
|
|
108
|
+
## Quickstart
|
|
109
|
+
|
|
110
|
+
`frames` is a table in the shape above.
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from facedyn import (
|
|
114
|
+
group_report, cross_validate_pipeline,
|
|
115
|
+
plot_roc_ovr, plot_confusion_matrix, plot_feature_effect,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# The participant is the unit of independence: check the groups first.
|
|
119
|
+
group_report(frames, "participant", label_col="emotion")
|
|
120
|
+
|
|
121
|
+
# Smoothing, normalisation, NMF, AU choice, features, cleaning, Boruta and
|
|
122
|
+
# the classifier are all refitted on the training participants of each fold.
|
|
123
|
+
result = cross_validate_pipeline(
|
|
124
|
+
frames, labels="emotion", groups="participant",
|
|
125
|
+
random_state=0, n_jobs=-1, keep_models=True,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
result.summary() # mean +- SD of the per-fold scores
|
|
129
|
+
result.oof_metrics() # pooled out-of-fold AUC per repeat (macro OvR for 3+ classes)
|
|
130
|
+
result.au_frequency() # how often each AU was chosen across folds
|
|
131
|
+
result.feature_frequency() # how often each feature survived selection
|
|
132
|
+
|
|
133
|
+
oof = result.oof[result.oof["repeat"] == 0]
|
|
134
|
+
plot_roc_ovr(oof["y_true"], oof[[f"proba_{c}" for c in result.classes]],
|
|
135
|
+
labels=result.classes)
|
|
136
|
+
plot_confusion_matrix(oof["y_true"], oof["y_pred"], labels=result.classes,
|
|
137
|
+
normalize="reference", annotate="both")
|
|
138
|
+
plot_feature_effect(result, features=result.feature_frequency().index[:3])
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
For matched-pairs data, build the groups with `pair_groups` (or
|
|
142
|
+
`pair_groups_from_filenames`) and pass them as `groups`. If you already have
|
|
143
|
+
a feature table that nothing has been fitted to, `cross_validate_grouped`
|
|
144
|
+
cross-validates it directly.
|
|
145
|
+
|
|
146
|
+
## Tutorials and worked example
|
|
147
|
+
|
|
148
|
+
A five-part interactive tutorial series in [`examples/`](examples/) walks
|
|
149
|
+
through the complete workflow on the public Cuve et al. (2026) facial emotion
|
|
150
|
+
dataset (456 videos, 42 participants, posed and spoken conditions), reproducing
|
|
151
|
+
the figures, tables, evaluation pitfall experiments, and 13-item reporting
|
|
152
|
+
checklist from the accompanying article:
|
|
153
|
+
|
|
154
|
+
1. [`01_data_preparation_and_splitting.ipynb`](examples/01_data_preparation_and_splitting.ipynb) — frame auditing, smoothing overlays (`plot_smoothing_comparison(..., mode="overlay")`), and participant grouped splitting.
|
|
155
|
+
2. [`02_nmf_facial_synergies.ipynb`](examples/02_nmf_facial_synergies.ipynb) — NMF rank diagnostics, starred basis heatmaps (`plot_nmf_basis_heatmap(..., mark_representative=True)`), face maps, and per-AU reconstruction $R^2$.
|
|
156
|
+
3. [`03_classification_and_interpretation.ipynb`](examples/03_classification_and_interpretation.ipynb) — fold-internal `cross_validate_pipeline()`, comparator baselines, ROC/confusion plots, Boruta stability clusters, and CV-averaged ALE.
|
|
157
|
+
4. [`04_evaluation_pitfalls.ipynb`](examples/04_evaluation_pitfalls.ipynb) — 2 × 2 data leakage comparison, 200-seed single-split variance vs repeated OOF CV, and duration shortcut audit.
|
|
158
|
+
5. [`05_reporting_checklist.ipynb`](examples/05_reporting_checklist.ipynb) — programmatic assembly of the 13-item software agnostic reporting checklist.
|
|
159
|
+
|
|
160
|
+
See [`examples/README.md`](examples/README.md) for environment setup, data
|
|
161
|
+
download instructions, and caching options.
|
|
162
|
+
|
|
163
|
+
## Scope
|
|
164
|
+
|
|
165
|
+
Classification of AU time series, binary or multiclass, from OpenFace
|
|
166
|
+
output. Continuous outcomes (regression) and other AU extractors are planned
|
|
167
|
+
for later versions.
|
|
168
|
+
|
|
169
|
+
## Development
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
python -m pip install -U pip # dependency groups need pip >= 25.1
|
|
173
|
+
pip install --group dev -e ".[viz]" # tests, ruff, mypy, pre-commit
|
|
174
|
+
pre-commit install # lint and format on every commit
|
|
175
|
+
pytest # fast tests, ~15 s
|
|
176
|
+
pytest --runslow # everything, including Boruta and R validation
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for the full workflow.
|
|
180
|
+
|
|
181
|
+
## Credits
|
|
182
|
+
|
|
183
|
+
NMF component face maps adapt the visualisation approach from
|
|
184
|
+
[py-feat](https://py-feat.org/) (Cheong et al., 2023).
|
|
185
|
+
|
|
186
|
+
Licensed under the MIT License.
|