fp-persistence-audit 0.1.2__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.
- fp_persistence/__init__.py +23 -0
- fp_persistence/_version.py +3 -0
- fp_persistence/persistence.py +29 -0
- fp_persistence/public_api.py +828 -0
- fp_persistence/public_types.py +919 -0
- fp_persistence/schema.py +10 -0
- fp_persistence_audit-0.1.2.dist-info/METADATA +450 -0
- fp_persistence_audit-0.1.2.dist-info/RECORD +11 -0
- fp_persistence_audit-0.1.2.dist-info/WHEEL +5 -0
- fp_persistence_audit-0.1.2.dist-info/licenses/LICENSE +201 -0
- fp_persistence_audit-0.1.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Public API for the generic false-positive persistence audit."""
|
|
2
|
+
|
|
3
|
+
from ._version import PACKAGE_VERSION as __version__
|
|
4
|
+
from .public_api import audit, flags_from_scores
|
|
5
|
+
from .public_types import (
|
|
6
|
+
AuditResult,
|
|
7
|
+
AuditStatus,
|
|
8
|
+
AuditValidationError,
|
|
9
|
+
ExposureSpec,
|
|
10
|
+
FlagSelection,
|
|
11
|
+
PermutationSpec,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"AuditResult",
|
|
16
|
+
"AuditStatus",
|
|
17
|
+
"AuditValidationError",
|
|
18
|
+
"ExposureSpec",
|
|
19
|
+
"FlagSelection",
|
|
20
|
+
"PermutationSpec",
|
|
21
|
+
"audit",
|
|
22
|
+
"flags_from_scores",
|
|
23
|
+
]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Entity exposure and repeated false-positive summaries."""
|
|
2
|
+
|
|
3
|
+
import pandas as pd
|
|
4
|
+
|
|
5
|
+
from .schema import PersistenceSummary
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def compute_repeat_fp_by_entity(
|
|
9
|
+
frame: pd.DataFrame, *, entity_column: str, legitimate_column: str,
|
|
10
|
+
false_positive_column: str, exposure_min: int, exposure_max: int | None,
|
|
11
|
+
minimum_false_positives: int = 2,
|
|
12
|
+
) -> pd.DataFrame:
|
|
13
|
+
"""Calculate eligibility from legitimate exposure and repeat-FP status."""
|
|
14
|
+
legitimate = frame.loc[frame[legitimate_column].astype(bool)]
|
|
15
|
+
result = legitimate.groupby(entity_column, dropna=False, sort=False)[false_positive_column].agg(
|
|
16
|
+
legitimate_exposure="size", false_positive_count="sum"
|
|
17
|
+
)
|
|
18
|
+
upper = True if exposure_max is None else result["legitimate_exposure"] <= exposure_max
|
|
19
|
+
result["eligible"] = (result["legitimate_exposure"] >= exposure_min) & upper
|
|
20
|
+
result["repeat_fp"] = result["false_positive_count"] >= minimum_false_positives
|
|
21
|
+
return result.reset_index()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def compute_persistence_summary(entity_frame: pd.DataFrame) -> PersistenceSummary:
|
|
25
|
+
"""Summarize repeated false positives among eligible entities."""
|
|
26
|
+
eligible = entity_frame.loc[entity_frame["eligible"].astype(bool)]
|
|
27
|
+
denominator = len(eligible)
|
|
28
|
+
numerator = int(eligible["repeat_fp"].sum())
|
|
29
|
+
return PersistenceSummary(numerator, denominator, numerator / denominator if denominator else float("nan"))
|