ectype-data 0.1.0__py3-none-any.whl
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.
- ectype/__init__.py +134 -0
- ectype/_version.py +5 -0
- ectype/authoring/__init__.py +13 -0
- ectype/authoring/builder.py +134 -0
- ectype/authoring/spec.py +555 -0
- ectype/calibration/__init__.py +26 -0
- ectype/calibration/adjustments.py +539 -0
- ectype/calibration/calibrator.py +781 -0
- ectype/cli.py +1181 -0
- ectype/compiler/__init__.py +1 -0
- ectype/compiler/plan.py +678 -0
- ectype/errors.py +43 -0
- ectype/fingerprint/__init__.py +1 -0
- ectype/fingerprint/comparison.py +746 -0
- ectype/fingerprint/container.py +408 -0
- ectype/fingerprint/core.py +263 -0
- ectype/fingerprint/disclosure.py +207 -0
- ectype/fingerprint/expressions.py +1317 -0
- ectype/fingerprint/schema.py +645 -0
- ectype/fingerprint/targets.py +352 -0
- ectype/generation/__init__.py +1 -0
- ectype/generation/enforce.py +163 -0
- ectype/generation/generator.py +525 -0
- ectype/generation/identifiers.py +235 -0
- ectype/generation/manifest.py +71 -0
- ectype/generation/parallel.py +229 -0
- ectype/io/__init__.py +16 -0
- ectype/io/adapters.py +224 -0
- ectype/io/sql.py +289 -0
- ectype/io/values.py +269 -0
- ectype/llm/__init__.py +27 -0
- ectype/llm/authoring.py +766 -0
- ectype/llm/providers.py +269 -0
- ectype/models/__init__.py +8 -0
- ectype/models/base.py +120 -0
- ectype/models/chain.py +2426 -0
- ectype/models/copulas.py +254 -0
- ectype/models/encoding.py +1117 -0
- ectype/models/forest.py +1087 -0
- ectype/models/marginals.py +2099 -0
- ectype/models/mixtures.py +336 -0
- ectype/models/neural/__init__.py +21 -0
- ectype/models/neural/adapter.py +638 -0
- ectype/models/neural/vae.py +432 -0
- ectype/models/vines.py +608 -0
- ectype/plugins.py +40 -0
- ectype/privacy/__init__.py +49 -0
- ectype/privacy/attacks.py +599 -0
- ectype/privacy/dp.py +313 -0
- ectype/privacy/report.py +364 -0
- ectype/profiler.py +783 -0
- ectype/profiling/__init__.py +1 -0
- ectype/profiling/bivariate.py +130 -0
- ectype/profiling/calendar.py +743 -0
- ectype/profiling/conditional.py +263 -0
- ectype/profiling/constraints.py +661 -0
- ectype/profiling/entity.py +1143 -0
- ectype/profiling/functional.py +651 -0
- ectype/profiling/multivariate.py +492 -0
- ectype/profiling/personal.py +277 -0
- ectype/profiling/pseudonym.py +370 -0
- ectype/profiling/reference.py +334 -0
- ectype/profiling/sketches.py +653 -0
- ectype/profiling/structural.py +1087 -0
- ectype/profiling/structure.py +1733 -0
- ectype/profiling/sums.py +1710 -0
- ectype/profiling/tolerance.py +435 -0
- ectype/profiling/univariate.py +555 -0
- ectype/py.typed +0 -0
- ectype/registry.py +48 -0
- ectype/relational/__init__.py +61 -0
- ectype/relational/container.py +212 -0
- ectype/relational/fit.py +633 -0
- ectype/relational/generate.py +418 -0
- ectype/relational/schema.py +280 -0
- ectype/relational/validate.py +288 -0
- ectype/reporting/__init__.py +439 -0
- ectype/reporting/adapter.py +2003 -0
- ectype/reporting/charts.py +964 -0
- ectype/reporting/drift.py +902 -0
- ectype/reporting/findings.py +622 -0
- ectype/reporting/fmt.py +429 -0
- ectype/reporting/render.py +1705 -0
- ectype/reporting/select.py +84 -0
- ectype/reporting/style.py +272 -0
- ectype/reporting/view.py +593 -0
- ectype/rng.py +33 -0
- ectype/scenarios/__init__.py +30 -0
- ectype/scenarios/feasibility.py +411 -0
- ectype/scenarios/merge.py +1392 -0
- ectype/scenarios/mutate.py +1613 -0
- ectype/temporal/__init__.py +80 -0
- ectype/temporal/contract.py +221 -0
- ectype/temporal/detect.py +431 -0
- ectype/temporal/events.py +946 -0
- ectype/temporal/panel.py +937 -0
- ectype/temporal/pipeline.py +192 -0
- ectype/temporal/regular.py +674 -0
- ectype/types.py +46 -0
- ectype/validation/__init__.py +1 -0
- ectype/validation/metrics/__init__.py +7 -0
- ectype/validation/metrics/base.py +68 -0
- ectype/validation/metrics/bivariate.py +353 -0
- ectype/validation/metrics/missingness.py +54 -0
- ectype/validation/metrics/multivariate.py +265 -0
- ectype/validation/metrics/temporal.py +596 -0
- ectype/validation/metrics/univariate.py +514 -0
- ectype/validation/report.py +627 -0
- ectype/validation/validator.py +707 -0
- ectype_data-0.1.0.dist-info/METADATA +376 -0
- ectype_data-0.1.0.dist-info/RECORD +115 -0
- ectype_data-0.1.0.dist-info/WHEEL +4 -0
- ectype_data-0.1.0.dist-info/entry_points.txt +2 -0
- ectype_data-0.1.0.dist-info/licenses/LICENSE +192 -0
- ectype_data-0.1.0.dist-info/licenses/NOTICE +5 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""Bivariate association profiler (M9).
|
|
2
|
+
|
|
3
|
+
``association_matrix`` computes a pairwise association *strength* in [0, 1] with the
|
|
4
|
+
type-appropriate measure and ranks candidate dependent pairs. It is diagnostic: it is used to
|
|
5
|
+
prioritise which pairs get bivariate targets and is not stored as a target itself.
|
|
6
|
+
|
|
7
|
+
Measures:
|
|
8
|
+
|
|
9
|
+
* numeric-like x numeric-like (continuous, discrete, datetime, boolean): ``|spearman|``
|
|
10
|
+
* categorical x categorical/boolean: bias-corrected Cramer's V
|
|
11
|
+
* categorical x numeric: bias-corrected correlation ratio (eta)
|
|
12
|
+
|
|
13
|
+
Rows with a null in either column are dropped per pair. Data are subsampled deterministically
|
|
14
|
+
to at most ``max_rows`` rows (default 20000).
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from itertools import combinations
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
import numpy as np
|
|
23
|
+
import polars as pl
|
|
24
|
+
|
|
25
|
+
from ectype.fingerprint.disclosure import coarsen, resolve_policy
|
|
26
|
+
from ectype.fingerprint.schema import ColumnSchema, DisclosurePolicySpec
|
|
27
|
+
from ectype.rng import stream
|
|
28
|
+
from ectype.types import LogicalType
|
|
29
|
+
from ectype.validation.metrics.bivariate import (
|
|
30
|
+
correlation_ratio,
|
|
31
|
+
cramers_v,
|
|
32
|
+
spearman,
|
|
33
|
+
)
|
|
34
|
+
from ectype.validation.metrics.univariate import (
|
|
35
|
+
category_codes_from_data,
|
|
36
|
+
is_category,
|
|
37
|
+
is_numeric_like,
|
|
38
|
+
numeric_values,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _measure_for(a: ColumnSchema, b: ColumnSchema) -> str | None:
|
|
43
|
+
cat_a = a.logical_type == LogicalType.CATEGORICAL
|
|
44
|
+
cat_b = b.logical_type == LogicalType.CATEGORICAL
|
|
45
|
+
if is_numeric_like(a) and is_numeric_like(b):
|
|
46
|
+
return "spearman"
|
|
47
|
+
if (cat_a or cat_b) and is_category(a) and is_category(b):
|
|
48
|
+
return "cramers_v"
|
|
49
|
+
if (cat_a and is_numeric_like(b)) or (cat_b and is_numeric_like(a)):
|
|
50
|
+
return "correlation_ratio"
|
|
51
|
+
return None
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def association_matrix(df: pl.DataFrame, columns: list[ColumnSchema],
|
|
55
|
+
policy: DisclosurePolicySpec | str | None = None, *,
|
|
56
|
+
max_pairs: int = 200, max_rows: int = 20_000, seed: int = 0
|
|
57
|
+
) -> dict[str, Any]:
|
|
58
|
+
"""Pairwise association strengths and ranked candidate dependent pairs.
|
|
59
|
+
|
|
60
|
+
Returns a JSON-safe dict::
|
|
61
|
+
|
|
62
|
+
{"columns": [...], "matrix": [[...]], # symmetric strengths (diag 1, NaN -> 0)
|
|
63
|
+
"pairs": [{"columns": [a, b], "measure": m, "strength": s}, ...], # all, sorted desc
|
|
64
|
+
"candidates": [...], # dependent pairs (s > threshold), <= max_pairs
|
|
65
|
+
"diagnostics": {"n_rows_used", "n_pairs", "threshold", "skipped_columns", ...}}
|
|
66
|
+
"""
|
|
67
|
+
pol = resolve_policy(policy)
|
|
68
|
+
usable = [c for c in columns if is_numeric_like(c) or is_category(c)]
|
|
69
|
+
skipped = [c.name for c in columns if c not in usable]
|
|
70
|
+
if df.height > max_rows:
|
|
71
|
+
idx = np.sort(stream(seed, "association", df.height).choice(df.height, max_rows,
|
|
72
|
+
replace=False))
|
|
73
|
+
sub = df.select([c.name for c in usable])[idx]
|
|
74
|
+
else:
|
|
75
|
+
sub = df.select([c.name for c in usable])
|
|
76
|
+
n = sub.height
|
|
77
|
+
|
|
78
|
+
num: dict[str, np.ndarray] = {}
|
|
79
|
+
cat: dict[str, tuple[np.ndarray, int]] = {}
|
|
80
|
+
for c in usable:
|
|
81
|
+
if is_numeric_like(c):
|
|
82
|
+
num[c.name] = numeric_values(sub[c.name], c)
|
|
83
|
+
if c.logical_type in (LogicalType.CATEGORICAL, LogicalType.BOOLEAN):
|
|
84
|
+
labels, codes, _ = category_codes_from_data(sub[c.name], pol)
|
|
85
|
+
cat[c.name] = (codes, len(labels))
|
|
86
|
+
|
|
87
|
+
names = [c.name for c in usable]
|
|
88
|
+
pos = {nm: i for i, nm in enumerate(names)}
|
|
89
|
+
mat = np.eye(len(names))
|
|
90
|
+
pairs: list[dict[str, Any]] = []
|
|
91
|
+
for a, b in combinations(usable, 2):
|
|
92
|
+
m = _measure_for(a, b)
|
|
93
|
+
if m is None:
|
|
94
|
+
continue
|
|
95
|
+
if m == "spearman":
|
|
96
|
+
s = abs(spearman(num[a.name], num[b.name]))
|
|
97
|
+
elif m == "cramers_v":
|
|
98
|
+
ca, ka = cat[a.name]
|
|
99
|
+
cb, kb = cat[b.name]
|
|
100
|
+
ok = np.isfinite(ca) & np.isfinite(cb)
|
|
101
|
+
s = cramers_v(ca[ok].astype(np.int64), cb[ok].astype(np.int64), ka, kb,
|
|
102
|
+
bias_correct=True)
|
|
103
|
+
else:
|
|
104
|
+
ccol, ncol = (a, b) if a.logical_type == LogicalType.CATEGORICAL else (b, a)
|
|
105
|
+
codes, k = cat[ccol.name]
|
|
106
|
+
y = num[ncol.name]
|
|
107
|
+
ok = np.isfinite(codes) & np.isfinite(y)
|
|
108
|
+
s = correlation_ratio(codes[ok].astype(np.int64), y[ok], k, bias_correct=True)
|
|
109
|
+
s = float(np.clip(s if np.isfinite(s) else 0.0, 0.0, 1.0))
|
|
110
|
+
s = coarsen(s, pol)
|
|
111
|
+
mat[pos[a.name], pos[b.name]] = mat[pos[b.name], pos[a.name]] = s
|
|
112
|
+
pairs.append({"columns": [a.name, b.name], "measure": m, "strength": s})
|
|
113
|
+
|
|
114
|
+
pairs.sort(key=lambda p: (-p["strength"], p["columns"][0], p["columns"][1]))
|
|
115
|
+
threshold = float(max(0.05, 3.0 / np.sqrt(max(n, 1))))
|
|
116
|
+
candidates = [p for p in pairs if p["strength"] > threshold][:max_pairs]
|
|
117
|
+
return {
|
|
118
|
+
"columns": names,
|
|
119
|
+
"matrix": [[float(v) for v in row] for row in mat],
|
|
120
|
+
"pairs": pairs,
|
|
121
|
+
"candidates": candidates,
|
|
122
|
+
"diagnostics": {
|
|
123
|
+
"n_rows_used": int(n),
|
|
124
|
+
"n_pairs": len(pairs),
|
|
125
|
+
"n_candidates": len(candidates),
|
|
126
|
+
"threshold": coarsen(threshold, pol),
|
|
127
|
+
"skipped_columns": skipped,
|
|
128
|
+
"max_pairs": int(max_pairs),
|
|
129
|
+
},
|
|
130
|
+
}
|