nexml 1.0.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.
Files changed (56) hide show
  1. nexml-1.0.0/LICENSE +21 -0
  2. nexml-1.0.0/PKG-INFO +92 -0
  3. nexml-1.0.0/README.md +45 -0
  4. nexml-1.0.0/nexml/__init__.py +27 -0
  5. nexml-1.0.0/nexml/__main__.py +31 -0
  6. nexml-1.0.0/nexml/core/__init__.py +4 -0
  7. nexml-1.0.0/nexml/core/auto_tuner.py +121 -0
  8. nexml-1.0.0/nexml/core/configuration.py +40 -0
  9. nexml-1.0.0/nexml/core/engine.py +491 -0
  10. nexml-1.0.0/nexml/core/progress.py +127 -0
  11. nexml-1.0.0/nexml/detection/__init__.py +12 -0
  12. nexml-1.0.0/nexml/detection/concept_drift.py +92 -0
  13. nexml-1.0.0/nexml/detection/data_drift.py +84 -0
  14. nexml-1.0.0/nexml/detection/data_quality.py +43 -0
  15. nexml-1.0.0/nexml/detection/spectral_drift.py +52 -0
  16. nexml-1.0.0/nexml/diagnosis/__init__.py +15 -0
  17. nexml-1.0.0/nexml/diagnosis/bayesian_diagnosis.py +43 -0
  18. nexml-1.0.0/nexml/diagnosis/feature_analysis.py +27 -0
  19. nexml-1.0.0/nexml/diagnosis/graph_root_cause.py +44 -0
  20. nexml-1.0.0/nexml/diagnosis/information_ranking.py +72 -0
  21. nexml-1.0.0/nexml/diagnosis/root_cause.py +29 -0
  22. nexml-1.0.0/nexml/diagnosis/segment_analysis.py +50 -0
  23. nexml-1.0.0/nexml/label_quality/__init__.py +5 -0
  24. nexml-1.0.0/nexml/label_quality/consistency.py +31 -0
  25. nexml-1.0.0/nexml/label_quality/label_error_report.py +41 -0
  26. nexml-1.0.0/nexml/label_quality/noise_detector.py +95 -0
  27. nexml-1.0.0/nexml/math/__init__.py +19 -0
  28. nexml-1.0.0/nexml/math/calculus.py +54 -0
  29. nexml-1.0.0/nexml/math/linear_algebra.py +88 -0
  30. nexml-1.0.0/nexml/math/optimization.py +67 -0
  31. nexml-1.0.0/nexml/recovery/__init__.py +4 -0
  32. nexml-1.0.0/nexml/recovery/intervention.py +180 -0
  33. nexml-1.0.0/nexml/recovery/recommendations.py +27 -0
  34. nexml-1.0.0/nexml/reporting/__init__.py +5 -0
  35. nexml-1.0.0/nexml/reporting/expert_diagnostics.py +147 -0
  36. nexml-1.0.0/nexml/reporting/plain_english.py +106 -0
  37. nexml-1.0.0/nexml/reporting/reports.py +134 -0
  38. nexml-1.0.0/nexml/validation/__init__.py +15 -0
  39. nexml-1.0.0/nexml/validation/comparison.py +55 -0
  40. nexml-1.0.0/nexml/validation/conformal.py +86 -0
  41. nexml-1.0.0/nexml/validation/performance.py +74 -0
  42. nexml-1.0.0/nexml/validation/stability.py +49 -0
  43. nexml-1.0.0/nexml.egg-info/PKG-INFO +92 -0
  44. nexml-1.0.0/nexml.egg-info/SOURCES.txt +54 -0
  45. nexml-1.0.0/nexml.egg-info/dependency_links.txt +1 -0
  46. nexml-1.0.0/nexml.egg-info/entry_points.txt +2 -0
  47. nexml-1.0.0/nexml.egg-info/requires.txt +24 -0
  48. nexml-1.0.0/nexml.egg-info/top_level.txt +1 -0
  49. nexml-1.0.0/pyproject.toml +87 -0
  50. nexml-1.0.0/setup.cfg +4 -0
  51. nexml-1.0.0/tests/test_leakage_and_metrics.py +118 -0
  52. nexml-1.0.0/tests/test_nexml.py +123 -0
  53. nexml-1.0.0/tests/test_regression.py +92 -0
  54. nexml-1.0.0/tests/test_v103_fixes.py +85 -0
  55. nexml-1.0.0/tests/test_v105.py +86 -0
  56. nexml-1.0.0/tests/test_v110.py +133 -0
nexml-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Samharison
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.
nexml-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,92 @@
1
+ Metadata-Version: 2.4
2
+ Name: nexml
3
+ Version: 1.0.0
4
+ Summary: NEXML v1.0.0 'Aegis': Nonlinear Evolutionary eXtensible Mathematical Learning — model-agnostic ML failure diagnosis, label quality analysis, and validated recovery for classification and regression.
5
+ Author-email: Sam <sam.sahoos20050@gmail.com>
6
+ Maintainer-email: Sam <sam.sahoos20050@gmail.com>
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/sam-x-specx/nexml-aegisv1.0.0
9
+ Project-URL: Documentation, https://github.com/sam-x-specx/nexml-aegisv1.0.0
10
+ Project-URL: Repository, https://github.com/sam-x-specx/nexml-aegisv1.0.0
11
+ Project-URL: Issues, https://github.com/sam-x-specx/nexml-aegisv1.0.0
12
+ Keywords: machine-learning,mlops,model-monitoring,data-drift,concept-drift,label-quality,model-reliability,failure-diagnosis,validated-recovery,nexml
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python :: 3
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: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: numpy>=1.24
28
+ Requires-Dist: pandas>=2.0
29
+ Requires-Dist: scipy>=1.10
30
+ Requires-Dist: scikit-learn>=1.3
31
+ Provides-Extra: explain
32
+ Requires-Dist: shap>=0.44; extra == "explain"
33
+ Provides-Extra: streaming
34
+ Requires-Dist: river>=0.21; extra == "streaming"
35
+ Provides-Extra: tuning
36
+ Requires-Dist: optuna>=3.4; extra == "tuning"
37
+ Provides-Extra: dev
38
+ Requires-Dist: pytest>=7.4; extra == "dev"
39
+ Requires-Dist: ruff>=0.4; extra == "dev"
40
+ Provides-Extra: all
41
+ Requires-Dist: shap>=0.44; extra == "all"
42
+ Requires-Dist: river>=0.21; extra == "all"
43
+ Requires-Dist: optuna>=3.4; extra == "all"
44
+ Requires-Dist: pytest>=7.4; extra == "all"
45
+ Requires-Dist: ruff>=0.4; extra == "all"
46
+ Dynamic: license-file
47
+
48
+ # NEXML v1.0.1 — "Aegis"
49
+
50
+ **Nonlinear Evolutionary eXtensible Mathematical Learning**
51
+
52
+ Model-agnostic ML failure diagnosis, label quality analysis, and validated recovery — for **classification and regression**.
53
+
54
+ ```bash
55
+ pip install nexml
56
+ ```
57
+
58
+ ## Quickstart (classification)
59
+
60
+ ```python
61
+ from nexml import NEXML
62
+
63
+ engine = NEXML(model=trained_model, task="classification")
64
+ engine.fit(reference_data=X_train, reference_target=y_train)
65
+ report = engine.analyze(new_data=X_new, new_target=y_new)
66
+
67
+ print(report.plain_english) # L1: one-sentence verdict
68
+ print(report.summary()) # L2: engineering report
69
+ report.expert_diagnostics() # L3: full math
70
+ ```
71
+
72
+ ## Quickstart (regression)
73
+
74
+ ```python
75
+ engine = NEXML(model=regressor, task="regression")
76
+ engine.fit(reference_data=X_train, reference_target=y_train)
77
+ report = engine.analyze(new_data=X_new, new_target=y_new)
78
+ print(report.plain_english) # "reduced mae from 18432.51 to 12104.77"
79
+ ```
80
+
81
+ ## What it does
82
+
83
+ 1. **Detection** — KS/chi-square drift, PCA/SVD multivariate drift, FFT spectral drift, missingness, unseen categories.
84
+ 2. **Diagnosis** — Bayesian cause probabilities, information-theoretic ranking, graph PageRank, segment analysis.
85
+ 3. **Label Quality** — confidence-learning noise detection (classification) / residual-quantile detection (regression), kNN consistency.
86
+ 4. **Recovery** — 6 candidate corrective actions, validated on held-out data.
87
+ 5. **Validation** — EGFDR objective `J(a) = gain − λ₁·cost − λ₂·risk`, 95% bootstrap CIs, task-aware metric direction.
88
+ 6. **Reporting** — three progressive layers (L1 / L2 / L3).
89
+
90
+ ## License
91
+
92
+ MIT
nexml-1.0.0/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # NEXML v1.0.1 — "Aegis"
2
+
3
+ **Nonlinear Evolutionary eXtensible Mathematical Learning**
4
+
5
+ Model-agnostic ML failure diagnosis, label quality analysis, and validated recovery — for **classification and regression**.
6
+
7
+ ```bash
8
+ pip install nexml
9
+ ```
10
+
11
+ ## Quickstart (classification)
12
+
13
+ ```python
14
+ from nexml import NEXML
15
+
16
+ engine = NEXML(model=trained_model, task="classification")
17
+ engine.fit(reference_data=X_train, reference_target=y_train)
18
+ report = engine.analyze(new_data=X_new, new_target=y_new)
19
+
20
+ print(report.plain_english) # L1: one-sentence verdict
21
+ print(report.summary()) # L2: engineering report
22
+ report.expert_diagnostics() # L3: full math
23
+ ```
24
+
25
+ ## Quickstart (regression)
26
+
27
+ ```python
28
+ engine = NEXML(model=regressor, task="regression")
29
+ engine.fit(reference_data=X_train, reference_target=y_train)
30
+ report = engine.analyze(new_data=X_new, new_target=y_new)
31
+ print(report.plain_english) # "reduced mae from 18432.51 to 12104.77"
32
+ ```
33
+
34
+ ## What it does
35
+
36
+ 1. **Detection** — KS/chi-square drift, PCA/SVD multivariate drift, FFT spectral drift, missingness, unseen categories.
37
+ 2. **Diagnosis** — Bayesian cause probabilities, information-theoretic ranking, graph PageRank, segment analysis.
38
+ 3. **Label Quality** — confidence-learning noise detection (classification) / residual-quantile detection (regression), kNN consistency.
39
+ 4. **Recovery** — 6 candidate corrective actions, validated on held-out data.
40
+ 5. **Validation** — EGFDR objective `J(a) = gain − λ₁·cost − λ₂·risk`, 95% bootstrap CIs, task-aware metric direction.
41
+ 6. **Reporting** — three progressive layers (L1 / L2 / L3).
42
+
43
+ ## License
44
+
45
+ MIT
@@ -0,0 +1,27 @@
1
+ """NEXML — Nonlinear Evolutionary eXtensible Mathematical Learning.
2
+
3
+ NEXML v1.0.0 "Aegis"
4
+ Model-agnostic ML failure diagnosis, label quality analysis,
5
+ and validated recovery. Works for classification and regression.
6
+
7
+ Quickstart:
8
+ >>> from nexml import NEXML
9
+ >>> engine = NEXML(model=trained_model, task="classification")
10
+ >>> engine.fit(reference_data=X_train, reference_target=y_train)
11
+ >>> report = engine.analyze(
12
+ ... new_data=X_new, new_target=y_new,
13
+ ... recent_labeled_data=X_recent, recent_labeled_target=y_recent,
14
+ ... validation_data=X_val, validation_target=y_val,
15
+ ... )
16
+ >>> print(report.plain_english)
17
+ """
18
+
19
+ from nexml.core.engine import NEXML
20
+ from nexml.core.configuration import NEXMLConfig
21
+
22
+ __version__ = "1.0.0"
23
+ __codename__ = "Aegis"
24
+ __author__ = "NEXML Research"
25
+ __license__ = "MIT"
26
+
27
+ __all__ = ["NEXML", "NEXMLConfig", "__version__", "__codename__"]
@@ -0,0 +1,31 @@
1
+ """NEXML CLI: `nexml` or `python -m nexml` prints the release banner."""
2
+
3
+ import sys
4
+
5
+ import nexml
6
+
7
+ BANNER = r"""
8
+ ███╗ ██╗███████╗██╗ ██╗███╗ ███╗██╗
9
+ ████╗ ██║██╔════╝╚██╗██╔╝████╗ ████║██║
10
+ ██╔██╗ ██║█████╗ ╚███╔╝ ██╔████╔██║██║
11
+ ██║╚██╗██║██╔══╝ ██╔██╗ ██║╚██╔╝██║██║
12
+ ██║ ╚████║███████╗██╔╝ ██╗██║ ╚═╝ ██║███████╗
13
+ ╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝
14
+ """
15
+
16
+
17
+ def main() -> None:
18
+ """Entry point for the `nexml` CLI command."""
19
+ print(BANNER)
20
+ print(f" NEXML v{nexml.__version__} — \"{nexml.__codename__}\"")
21
+ print(" Nonlinear Evolutionary eXtensible Mathematical Learning")
22
+ print(" Model-agnostic ML failure diagnosis, label quality analysis,")
23
+ print(" and validated recovery — for classification and regression.")
24
+ print()
25
+ print(f" Python {sys.version.split()[0]}")
26
+ print(" MIT License · https://github.com/sam-x-specx/nexml-aegisv1.0.0")
27
+ print()
28
+
29
+
30
+ if __name__ == "__main__":
31
+ main()
@@ -0,0 +1,4 @@
1
+ from nexml.core.engine import NEXML
2
+ from nexml.core.configuration import NEXMLConfig
3
+
4
+ __all__ = ["NEXML", "NEXMLConfig"]
@@ -0,0 +1,121 @@
1
+ """Bayesian optimization of NEXML configuration parameters.
2
+
3
+ v1.0.8: More descriptive lambda_source when tuning fails to improve objective.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import numpy as np
9
+
10
+ try:
11
+ import optuna
12
+ _HAS_OPTUNA = True
13
+ except ImportError: # pragma: no cover
14
+ _HAS_OPTUNA = False
15
+
16
+
17
+ _DEFAULT_LAMBDA_COST = 0.05
18
+ _DEFAULT_LAMBDA_RISK = 0.5
19
+
20
+
21
+ def tune_lambdas(
22
+ validation_results: list[dict],
23
+ higher_is_better: bool = True,
24
+ n_trials: int = 30,
25
+ seed: int = 42,
26
+ gain_scale: float = 1.0,
27
+ ) -> dict:
28
+ """Tune λ₁ (cost), λ₂ (risk) to produce EXACTLY ONE clear winner.
29
+
30
+ Returns:
31
+ {"lambda_cost": float, "lambda_risk": float, "lambda_source": str}
32
+ where lambda_source is "tuned" or a descriptive "default (...)".
33
+ """
34
+ if not validation_results:
35
+ return _defaults("default (empty validation)")
36
+
37
+ if higher_is_better:
38
+ gains = np.array(
39
+ [r["metric"] - r["baseline_metric"] for r in validation_results], dtype=float
40
+ )
41
+ else:
42
+ gains = np.array(
43
+ [r["baseline_metric"] - r["metric"] for r in validation_results], dtype=float
44
+ )
45
+ costs = np.array(
46
+ [min(r["cost_seconds"] / 60.0, 1.0) for r in validation_results], dtype=float
47
+ )
48
+ risks = np.array([r["risk"] for r in validation_results], dtype=float)
49
+
50
+ # No action has positive gain → tuning cannot help; return defaults.
51
+ gains = gains / gain_scale
52
+ if not np.any(gains > 0):
53
+ return _defaults("default (no action beat baseline)")
54
+
55
+ # Lexicographic objective:
56
+ # 1) Prefer accepted_count == 1 (highest priority)
57
+ # 2) Among configurations with accepted_count == 1, maximize gain
58
+ # 3) If accepted_count != 1, score = -|accepted_count - 1| * penalty
59
+ def objective(lam1: float, lam2: float) -> float:
60
+ J = gains - lam1 * costs - lam2 * risks
61
+ accepted = int((J > 0).sum())
62
+ if accepted == 1:
63
+ # Excellent: one clear winner. Score = its gain.
64
+ return float(gains[J > 0][0])
65
+ if accepted == 0:
66
+ # Bad: nothing works. Score strictly below any 1-accepted solution.
67
+ return -100.0
68
+ # 2+ accepted: heavily penalize, so tuning pushes toward exactly 1.
69
+ accepted_gains = np.sort(gains[J > 0])[::-1]
70
+ best = float(accepted_gains[0])
71
+ return best - 0.1 * (accepted - 1)
72
+
73
+ # Baseline: λ = 0 (unpenalized). If tuning can't beat this, stay at 0.
74
+ zero_score = objective(0.0, 0.0)
75
+
76
+ if not _HAS_OPTUNA:
77
+ best = {"lambda_cost": 0.0, "lambda_risk": 0.0}
78
+ best_score = zero_score
79
+ for lam1 in np.linspace(0.0, 0.5, 11):
80
+ for lam2 in np.linspace(0.0, 2.0, 11):
81
+ score = objective(float(lam1), float(lam2))
82
+ if score > best_score + 1e-9:
83
+ best_score = score
84
+ best = {"lambda_cost": float(lam1), "lambda_risk": float(lam2)}
85
+ if best["lambda_cost"] == 0.0 and best["lambda_risk"] == 0.0:
86
+ return _defaults("default (tuning did not improve objective)")
87
+ return {
88
+ "lambda_cost": best["lambda_cost"],
89
+ "lambda_risk": best["lambda_risk"],
90
+ "lambda_source": "tuned",
91
+ }
92
+
93
+ optuna.logging.set_verbosity(optuna.logging.WARNING)
94
+
95
+ def optuna_obj(trial):
96
+ lam1 = trial.suggest_float("lambda_cost", 0.0, 0.5)
97
+ lam2 = trial.suggest_float("lambda_risk", 0.0, 2.0)
98
+ return objective(lam1, lam2)
99
+
100
+ study = optuna.create_study(
101
+ direction="maximize", sampler=optuna.samplers.TPESampler(seed=seed)
102
+ )
103
+ study.optimize(optuna_obj, n_trials=n_trials, show_progress_bar=False)
104
+
105
+ best_lam1 = float(study.best_params["lambda_cost"])
106
+ best_lam2 = float(study.best_params["lambda_risk"])
107
+ best_score = float(study.best_value)
108
+
109
+ # If tuning didn't beat λ = 0, return defaults to avoid false "tuned" label.
110
+ if best_score <= zero_score + 1e-9:
111
+ return _defaults("default (tuning did not improve objective)")
112
+
113
+ return {"lambda_cost": best_lam1, "lambda_risk": best_lam2, "lambda_source": "tuned"}
114
+
115
+
116
+ def _defaults(source: str) -> dict:
117
+ return {
118
+ "lambda_cost": _DEFAULT_LAMBDA_COST,
119
+ "lambda_risk": _DEFAULT_LAMBDA_RISK,
120
+ "lambda_source": source,
121
+ }
@@ -0,0 +1,40 @@
1
+ """NEXML configuration."""
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Literal
5
+
6
+
7
+ @dataclass
8
+ class NEXMLConfig:
9
+ task: Literal["classification", "regression"] = "classification"
10
+ drift_alpha: float = 0.05
11
+ effect_size_threshold: float = 0.10
12
+ importance_weight: float = 0.4
13
+ drift_weight: float = 0.4
14
+ error_weight: float = 0.2
15
+ cost_lambda: float = 0.05
16
+ risk_lambda: float = 0.5
17
+ validation_chunks: int = 5
18
+ min_performance_gain: float = 0.005
19
+ metric: str = ""
20
+
21
+ auto_tune: bool = True
22
+ # FFT drift only means something when rows are an ordered time series.
23
+ # Off by default; enable it for time-ordered data.
24
+ spectral_drift: bool = False
25
+ bayesian_diagnosis: bool = True
26
+ information_ranking: bool = True
27
+ graph_root_cause: bool = True
28
+ conformal_bounds: bool = True
29
+ label_quality: bool = True
30
+
31
+ def resolved_metric(self) -> str:
32
+ if self.metric:
33
+ return self.metric
34
+ return "f1" if self.task == "classification" else "mae"
35
+
36
+ def higher_is_better(self) -> bool:
37
+ """F1 is higher-better; MAE/RMSE are lower-better; R² is higher-better."""
38
+ if self.task == "classification":
39
+ return True
40
+ return self.resolved_metric() in ("r2",)