ml4t-diagnostic 0.1.0a1__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.
- ml4t/diagnostic/AGENT.md +25 -0
- ml4t/diagnostic/__init__.py +166 -0
- ml4t/diagnostic/backends/__init__.py +10 -0
- ml4t/diagnostic/backends/adapter.py +192 -0
- ml4t/diagnostic/backends/polars_backend.py +899 -0
- ml4t/diagnostic/caching/__init__.py +40 -0
- ml4t/diagnostic/caching/cache.py +331 -0
- ml4t/diagnostic/caching/decorators.py +131 -0
- ml4t/diagnostic/caching/smart_cache.py +339 -0
- ml4t/diagnostic/config/AGENT.md +24 -0
- ml4t/diagnostic/config/README.md +267 -0
- ml4t/diagnostic/config/__init__.py +219 -0
- ml4t/diagnostic/config/barrier_config.py +277 -0
- ml4t/diagnostic/config/base.py +301 -0
- ml4t/diagnostic/config/event_config.py +148 -0
- ml4t/diagnostic/config/feature_config.py +404 -0
- ml4t/diagnostic/config/multi_signal_config.py +55 -0
- ml4t/diagnostic/config/portfolio_config.py +215 -0
- ml4t/diagnostic/config/report_config.py +391 -0
- ml4t/diagnostic/config/sharpe_config.py +202 -0
- ml4t/diagnostic/config/signal_config.py +206 -0
- ml4t/diagnostic/config/trade_analysis_config.py +310 -0
- ml4t/diagnostic/config/validation.py +279 -0
- ml4t/diagnostic/core/__init__.py +29 -0
- ml4t/diagnostic/core/numba_utils.py +315 -0
- ml4t/diagnostic/core/purging.py +372 -0
- ml4t/diagnostic/core/sampling.py +471 -0
- ml4t/diagnostic/errors/__init__.py +205 -0
- ml4t/diagnostic/evaluation/AGENT.md +26 -0
- ml4t/diagnostic/evaluation/__init__.py +437 -0
- ml4t/diagnostic/evaluation/autocorrelation.py +531 -0
- ml4t/diagnostic/evaluation/barrier_analysis.py +1050 -0
- ml4t/diagnostic/evaluation/binary_metrics.py +910 -0
- ml4t/diagnostic/evaluation/dashboard.py +715 -0
- ml4t/diagnostic/evaluation/diagnostic_plots.py +1037 -0
- ml4t/diagnostic/evaluation/distribution/__init__.py +499 -0
- ml4t/diagnostic/evaluation/distribution/moments.py +299 -0
- ml4t/diagnostic/evaluation/distribution/tails.py +777 -0
- ml4t/diagnostic/evaluation/distribution/tests.py +470 -0
- ml4t/diagnostic/evaluation/drift/__init__.py +139 -0
- ml4t/diagnostic/evaluation/drift/analysis.py +432 -0
- ml4t/diagnostic/evaluation/drift/domain_classifier.py +517 -0
- ml4t/diagnostic/evaluation/drift/population_stability_index.py +310 -0
- ml4t/diagnostic/evaluation/drift/wasserstein.py +388 -0
- ml4t/diagnostic/evaluation/event_analysis.py +647 -0
- ml4t/diagnostic/evaluation/excursion.py +390 -0
- ml4t/diagnostic/evaluation/feature_diagnostics.py +873 -0
- ml4t/diagnostic/evaluation/feature_outcome.py +666 -0
- ml4t/diagnostic/evaluation/framework.py +935 -0
- ml4t/diagnostic/evaluation/metric_registry.py +255 -0
- ml4t/diagnostic/evaluation/metrics/AGENT.md +23 -0
- ml4t/diagnostic/evaluation/metrics/__init__.py +133 -0
- ml4t/diagnostic/evaluation/metrics/basic.py +160 -0
- ml4t/diagnostic/evaluation/metrics/conditional_ic.py +469 -0
- ml4t/diagnostic/evaluation/metrics/feature_outcome.py +475 -0
- ml4t/diagnostic/evaluation/metrics/ic_statistics.py +446 -0
- ml4t/diagnostic/evaluation/metrics/importance_analysis.py +338 -0
- ml4t/diagnostic/evaluation/metrics/importance_classical.py +375 -0
- ml4t/diagnostic/evaluation/metrics/importance_mda.py +371 -0
- ml4t/diagnostic/evaluation/metrics/importance_shap.py +715 -0
- ml4t/diagnostic/evaluation/metrics/information_coefficient.py +527 -0
- ml4t/diagnostic/evaluation/metrics/interactions.py +772 -0
- ml4t/diagnostic/evaluation/metrics/monotonicity.py +226 -0
- ml4t/diagnostic/evaluation/metrics/risk_adjusted.py +324 -0
- ml4t/diagnostic/evaluation/multi_signal.py +550 -0
- ml4t/diagnostic/evaluation/portfolio_analysis/__init__.py +83 -0
- ml4t/diagnostic/evaluation/portfolio_analysis/analysis.py +734 -0
- ml4t/diagnostic/evaluation/portfolio_analysis/metrics.py +589 -0
- ml4t/diagnostic/evaluation/portfolio_analysis/results.py +334 -0
- ml4t/diagnostic/evaluation/report_generation.py +824 -0
- ml4t/diagnostic/evaluation/signal_selector.py +452 -0
- ml4t/diagnostic/evaluation/stat_registry.py +139 -0
- ml4t/diagnostic/evaluation/stationarity/__init__.py +97 -0
- ml4t/diagnostic/evaluation/stationarity/analysis.py +518 -0
- ml4t/diagnostic/evaluation/stationarity/augmented_dickey_fuller.py +296 -0
- ml4t/diagnostic/evaluation/stationarity/kpss_test.py +308 -0
- ml4t/diagnostic/evaluation/stationarity/phillips_perron.py +365 -0
- ml4t/diagnostic/evaluation/stats/AGENT.md +43 -0
- ml4t/diagnostic/evaluation/stats/__init__.py +191 -0
- ml4t/diagnostic/evaluation/stats/backtest_overfitting.py +219 -0
- ml4t/diagnostic/evaluation/stats/bootstrap.py +228 -0
- ml4t/diagnostic/evaluation/stats/deflated_sharpe_ratio.py +591 -0
- ml4t/diagnostic/evaluation/stats/false_discovery_rate.py +295 -0
- ml4t/diagnostic/evaluation/stats/hac_standard_errors.py +108 -0
- ml4t/diagnostic/evaluation/stats/minimum_track_record.py +408 -0
- ml4t/diagnostic/evaluation/stats/moments.py +164 -0
- ml4t/diagnostic/evaluation/stats/rademacher_adjustment.py +436 -0
- ml4t/diagnostic/evaluation/stats/reality_check.py +155 -0
- ml4t/diagnostic/evaluation/stats/sharpe_inference.py +219 -0
- ml4t/diagnostic/evaluation/themes.py +330 -0
- ml4t/diagnostic/evaluation/threshold_analysis.py +957 -0
- ml4t/diagnostic/evaluation/trade_analysis.py +1136 -0
- ml4t/diagnostic/evaluation/trade_dashboard/__init__.py +32 -0
- ml4t/diagnostic/evaluation/trade_dashboard/app.py +315 -0
- ml4t/diagnostic/evaluation/trade_dashboard/export/__init__.py +18 -0
- ml4t/diagnostic/evaluation/trade_dashboard/export/csv.py +82 -0
- ml4t/diagnostic/evaluation/trade_dashboard/export/html.py +276 -0
- ml4t/diagnostic/evaluation/trade_dashboard/io.py +166 -0
- ml4t/diagnostic/evaluation/trade_dashboard/normalize.py +304 -0
- ml4t/diagnostic/evaluation/trade_dashboard/stats.py +386 -0
- ml4t/diagnostic/evaluation/trade_dashboard/style.py +79 -0
- ml4t/diagnostic/evaluation/trade_dashboard/tabs/__init__.py +21 -0
- ml4t/diagnostic/evaluation/trade_dashboard/tabs/patterns.py +354 -0
- ml4t/diagnostic/evaluation/trade_dashboard/tabs/shap_analysis.py +280 -0
- ml4t/diagnostic/evaluation/trade_dashboard/tabs/stat_validation.py +186 -0
- ml4t/diagnostic/evaluation/trade_dashboard/tabs/worst_trades.py +236 -0
- ml4t/diagnostic/evaluation/trade_dashboard/types.py +129 -0
- ml4t/diagnostic/evaluation/trade_shap/__init__.py +102 -0
- ml4t/diagnostic/evaluation/trade_shap/alignment.py +188 -0
- ml4t/diagnostic/evaluation/trade_shap/characterize.py +413 -0
- ml4t/diagnostic/evaluation/trade_shap/cluster.py +302 -0
- ml4t/diagnostic/evaluation/trade_shap/explain.py +208 -0
- ml4t/diagnostic/evaluation/trade_shap/hypotheses/__init__.py +23 -0
- ml4t/diagnostic/evaluation/trade_shap/hypotheses/generator.py +290 -0
- ml4t/diagnostic/evaluation/trade_shap/hypotheses/matcher.py +251 -0
- ml4t/diagnostic/evaluation/trade_shap/hypotheses/templates.yaml +467 -0
- ml4t/diagnostic/evaluation/trade_shap/models.py +386 -0
- ml4t/diagnostic/evaluation/trade_shap/normalize.py +116 -0
- ml4t/diagnostic/evaluation/trade_shap/pipeline.py +263 -0
- ml4t/diagnostic/evaluation/trade_shap_dashboard.py +283 -0
- ml4t/diagnostic/evaluation/trade_shap_diagnostics.py +588 -0
- ml4t/diagnostic/evaluation/validated_cv.py +535 -0
- ml4t/diagnostic/evaluation/visualization.py +1050 -0
- ml4t/diagnostic/evaluation/volatility/__init__.py +45 -0
- ml4t/diagnostic/evaluation/volatility/analysis.py +351 -0
- ml4t/diagnostic/evaluation/volatility/arch.py +258 -0
- ml4t/diagnostic/evaluation/volatility/garch.py +460 -0
- ml4t/diagnostic/integration/__init__.py +48 -0
- ml4t/diagnostic/integration/backtest_contract.py +671 -0
- ml4t/diagnostic/integration/data_contract.py +316 -0
- ml4t/diagnostic/integration/engineer_contract.py +226 -0
- ml4t/diagnostic/logging/__init__.py +77 -0
- ml4t/diagnostic/logging/logger.py +245 -0
- ml4t/diagnostic/logging/performance.py +234 -0
- ml4t/diagnostic/logging/progress.py +234 -0
- ml4t/diagnostic/logging/wandb.py +412 -0
- ml4t/diagnostic/metrics/__init__.py +9 -0
- ml4t/diagnostic/metrics/percentiles.py +128 -0
- ml4t/diagnostic/py.typed +1 -0
- ml4t/diagnostic/reporting/__init__.py +43 -0
- ml4t/diagnostic/reporting/base.py +130 -0
- ml4t/diagnostic/reporting/html_renderer.py +275 -0
- ml4t/diagnostic/reporting/json_renderer.py +51 -0
- ml4t/diagnostic/reporting/markdown_renderer.py +117 -0
- ml4t/diagnostic/results/AGENT.md +24 -0
- ml4t/diagnostic/results/__init__.py +105 -0
- ml4t/diagnostic/results/barrier_results/__init__.py +36 -0
- ml4t/diagnostic/results/barrier_results/hit_rate.py +304 -0
- ml4t/diagnostic/results/barrier_results/precision_recall.py +266 -0
- ml4t/diagnostic/results/barrier_results/profit_factor.py +297 -0
- ml4t/diagnostic/results/barrier_results/tearsheet.py +397 -0
- ml4t/diagnostic/results/barrier_results/time_to_target.py +305 -0
- ml4t/diagnostic/results/barrier_results/validation.py +38 -0
- ml4t/diagnostic/results/base.py +177 -0
- ml4t/diagnostic/results/event_results.py +349 -0
- ml4t/diagnostic/results/feature_results.py +787 -0
- ml4t/diagnostic/results/multi_signal_results.py +431 -0
- ml4t/diagnostic/results/portfolio_results.py +281 -0
- ml4t/diagnostic/results/sharpe_results.py +448 -0
- ml4t/diagnostic/results/signal_results/__init__.py +74 -0
- ml4t/diagnostic/results/signal_results/ic.py +581 -0
- ml4t/diagnostic/results/signal_results/irtc.py +110 -0
- ml4t/diagnostic/results/signal_results/quantile.py +392 -0
- ml4t/diagnostic/results/signal_results/tearsheet.py +456 -0
- ml4t/diagnostic/results/signal_results/turnover.py +213 -0
- ml4t/diagnostic/results/signal_results/validation.py +147 -0
- ml4t/diagnostic/signal/AGENT.md +17 -0
- ml4t/diagnostic/signal/__init__.py +69 -0
- ml4t/diagnostic/signal/_report.py +152 -0
- ml4t/diagnostic/signal/_utils.py +261 -0
- ml4t/diagnostic/signal/core.py +275 -0
- ml4t/diagnostic/signal/quantile.py +148 -0
- ml4t/diagnostic/signal/result.py +214 -0
- ml4t/diagnostic/signal/signal_ic.py +129 -0
- ml4t/diagnostic/signal/turnover.py +182 -0
- ml4t/diagnostic/splitters/AGENT.md +19 -0
- ml4t/diagnostic/splitters/__init__.py +36 -0
- ml4t/diagnostic/splitters/base.py +501 -0
- ml4t/diagnostic/splitters/calendar.py +421 -0
- ml4t/diagnostic/splitters/calendar_config.py +91 -0
- ml4t/diagnostic/splitters/combinatorial.py +1064 -0
- ml4t/diagnostic/splitters/config.py +322 -0
- ml4t/diagnostic/splitters/cpcv/__init__.py +57 -0
- ml4t/diagnostic/splitters/cpcv/combinations.py +119 -0
- ml4t/diagnostic/splitters/cpcv/partitioning.py +263 -0
- ml4t/diagnostic/splitters/cpcv/purge_engine.py +379 -0
- ml4t/diagnostic/splitters/cpcv/windows.py +190 -0
- ml4t/diagnostic/splitters/group_isolation.py +329 -0
- ml4t/diagnostic/splitters/persistence.py +316 -0
- ml4t/diagnostic/splitters/utils.py +207 -0
- ml4t/diagnostic/splitters/walk_forward.py +757 -0
- ml4t/diagnostic/utils/__init__.py +42 -0
- ml4t/diagnostic/utils/config.py +542 -0
- ml4t/diagnostic/utils/dependencies.py +318 -0
- ml4t/diagnostic/utils/sessions.py +127 -0
- ml4t/diagnostic/validation/__init__.py +54 -0
- ml4t/diagnostic/validation/dataframe.py +274 -0
- ml4t/diagnostic/validation/returns.py +280 -0
- ml4t/diagnostic/validation/timeseries.py +299 -0
- ml4t/diagnostic/visualization/AGENT.md +19 -0
- ml4t/diagnostic/visualization/__init__.py +223 -0
- ml4t/diagnostic/visualization/backtest/__init__.py +98 -0
- ml4t/diagnostic/visualization/backtest/cost_attribution.py +762 -0
- ml4t/diagnostic/visualization/backtest/executive_summary.py +895 -0
- ml4t/diagnostic/visualization/backtest/interactive_controls.py +673 -0
- ml4t/diagnostic/visualization/backtest/statistical_validity.py +874 -0
- ml4t/diagnostic/visualization/backtest/tearsheet.py +565 -0
- ml4t/diagnostic/visualization/backtest/template_system.py +373 -0
- ml4t/diagnostic/visualization/backtest/trade_plots.py +1172 -0
- ml4t/diagnostic/visualization/barrier_plots.py +782 -0
- ml4t/diagnostic/visualization/core.py +1060 -0
- ml4t/diagnostic/visualization/dashboards/__init__.py +36 -0
- ml4t/diagnostic/visualization/dashboards/base.py +582 -0
- ml4t/diagnostic/visualization/dashboards/importance.py +801 -0
- ml4t/diagnostic/visualization/dashboards/interaction.py +263 -0
- ml4t/diagnostic/visualization/dashboards.py +43 -0
- ml4t/diagnostic/visualization/data_extraction/__init__.py +48 -0
- ml4t/diagnostic/visualization/data_extraction/importance.py +649 -0
- ml4t/diagnostic/visualization/data_extraction/interaction.py +504 -0
- ml4t/diagnostic/visualization/data_extraction/types.py +113 -0
- ml4t/diagnostic/visualization/data_extraction/validation.py +66 -0
- ml4t/diagnostic/visualization/feature_plots.py +888 -0
- ml4t/diagnostic/visualization/interaction_plots.py +618 -0
- ml4t/diagnostic/visualization/portfolio/__init__.py +41 -0
- ml4t/diagnostic/visualization/portfolio/dashboard.py +514 -0
- ml4t/diagnostic/visualization/portfolio/drawdown_plots.py +341 -0
- ml4t/diagnostic/visualization/portfolio/returns_plots.py +487 -0
- ml4t/diagnostic/visualization/portfolio/risk_plots.py +301 -0
- ml4t/diagnostic/visualization/report_generation.py +1343 -0
- ml4t/diagnostic/visualization/signal/__init__.py +103 -0
- ml4t/diagnostic/visualization/signal/dashboard.py +911 -0
- ml4t/diagnostic/visualization/signal/event_plots.py +514 -0
- ml4t/diagnostic/visualization/signal/ic_plots.py +635 -0
- ml4t/diagnostic/visualization/signal/multi_signal_dashboard.py +974 -0
- ml4t/diagnostic/visualization/signal/multi_signal_plots.py +603 -0
- ml4t/diagnostic/visualization/signal/quantile_plots.py +625 -0
- ml4t/diagnostic/visualization/signal/turnover_plots.py +400 -0
- ml4t/diagnostic/visualization/trade_shap/__init__.py +90 -0
- ml4t_diagnostic-0.1.0a1.dist-info/METADATA +1044 -0
- ml4t_diagnostic-0.1.0a1.dist-info/RECORD +242 -0
- ml4t_diagnostic-0.1.0a1.dist-info/WHEEL +4 -0
- ml4t_diagnostic-0.1.0a1.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"""Feature interaction dashboard for deep-dive analysis.
|
|
2
|
+
|
|
3
|
+
This module provides the FeatureInteractionDashboard class for creating
|
|
4
|
+
standalone dashboards focused on feature interaction analysis.
|
|
5
|
+
|
|
6
|
+
Note: Currently a scaffold implementation. For working interaction
|
|
7
|
+
visualizations, use FeatureImportanceDashboard with interaction_results.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from typing import Any, Literal
|
|
13
|
+
|
|
14
|
+
from ..data_extraction import InteractionVizData, extract_interaction_viz_data
|
|
15
|
+
from .base import BaseDashboard, DashboardSection
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class FeatureInteractionDashboard(BaseDashboard):
|
|
19
|
+
"""Standalone dashboard for deep-dive feature interaction analysis.
|
|
20
|
+
|
|
21
|
+
**⚠️ NOTE**: Currently a scaffold implementation (network, matrix, per-feature
|
|
22
|
+
sections are placeholders). For working interaction visualizations, use
|
|
23
|
+
``FeatureImportanceDashboard`` with ``interaction_results`` parameter, which
|
|
24
|
+
provides network graph, interaction matrix, and top pairs table.
|
|
25
|
+
|
|
26
|
+
**Planned Features** (when fully implemented):
|
|
27
|
+
- **Network View**: Interactive force-directed graph with filtering/drill-down
|
|
28
|
+
- **Matrix View**: Large heatmap with clustering and sorting controls
|
|
29
|
+
- **Per-Feature**: Individual feature interaction profiles with charts
|
|
30
|
+
- **Cluster Analysis**: Automatic grouping of interacting feature sets
|
|
31
|
+
- **Insights**: Auto-generated interpretation and recommendations
|
|
32
|
+
|
|
33
|
+
This dashboard is intended for scenarios where you want a dedicated,
|
|
34
|
+
interaction-only report (no importance analysis). When implemented, it will
|
|
35
|
+
provide more advanced interaction-specific features than the integrated view
|
|
36
|
+
in FeatureImportanceDashboard.
|
|
37
|
+
|
|
38
|
+
Examples
|
|
39
|
+
--------
|
|
40
|
+
**Current Usage (Scaffolding)**
|
|
41
|
+
|
|
42
|
+
>>> from ml4t.diagnostic.evaluation import compute_shap_interactions
|
|
43
|
+
>>> from ml4t.diagnostic.visualization import FeatureInteractionDashboard
|
|
44
|
+
>>>
|
|
45
|
+
>>> # Compute interactions
|
|
46
|
+
>>> results = compute_shap_interactions(model, X_train,
|
|
47
|
+
... feature_names=X_train.columns)
|
|
48
|
+
>>>
|
|
49
|
+
>>> # Create dashboard (generates scaffold with insights only)
|
|
50
|
+
>>> dashboard = FeatureInteractionDashboard(
|
|
51
|
+
... title="Feature Interaction Deep-Dive",
|
|
52
|
+
... theme="dark",
|
|
53
|
+
... min_interaction_strength=0.1
|
|
54
|
+
... )
|
|
55
|
+
>>> dashboard.save("interaction_dashboard.html", results)
|
|
56
|
+
>>> # ⚠️ Network/matrix/per-feature sections will show placeholders
|
|
57
|
+
|
|
58
|
+
**Recommended Alternative (Fully Implemented)**
|
|
59
|
+
|
|
60
|
+
>>> from ml4t.diagnostic.evaluation import analyze_ml_importance, compute_shap_interactions
|
|
61
|
+
>>> from ml4t.diagnostic.visualization import FeatureImportanceDashboard
|
|
62
|
+
>>>
|
|
63
|
+
>>> # Run importance analysis
|
|
64
|
+
>>> importance_results = analyze_ml_importance(
|
|
65
|
+
... model, X_train, y_train,
|
|
66
|
+
... methods=['mdi', 'pfi'],
|
|
67
|
+
... feature_names=X_train.columns
|
|
68
|
+
... )
|
|
69
|
+
>>>
|
|
70
|
+
>>> # Compute interactions
|
|
71
|
+
>>> interaction_results = compute_shap_interactions(
|
|
72
|
+
... model, X_train,
|
|
73
|
+
... feature_names=X_train.columns
|
|
74
|
+
... )
|
|
75
|
+
>>>
|
|
76
|
+
>>> # Use FeatureImportanceDashboard with interactions
|
|
77
|
+
>>> dashboard = FeatureImportanceDashboard(
|
|
78
|
+
... title="Complete Analysis (Importance + Interactions)"
|
|
79
|
+
... )
|
|
80
|
+
>>> dashboard.save(
|
|
81
|
+
... "full_dashboard.html",
|
|
82
|
+
... analysis_results=importance_results,
|
|
83
|
+
... interaction_results=interaction_results # Adds 3 interaction sections
|
|
84
|
+
... )
|
|
85
|
+
>>> # ✅ Includes: network graph, interaction matrix, top pairs table
|
|
86
|
+
|
|
87
|
+
Notes
|
|
88
|
+
-----
|
|
89
|
+
- Currently only insights section is implemented
|
|
90
|
+
- Network/matrix/per-feature sections show placeholder messages
|
|
91
|
+
- For working interaction visualizations, use ``FeatureImportanceDashboard``
|
|
92
|
+
- Future implementation will add: force-directed layout, clustering,
|
|
93
|
+
filtering, drill-down, comparative analysis across datasets
|
|
94
|
+
|
|
95
|
+
See Also
|
|
96
|
+
--------
|
|
97
|
+
FeatureImportanceDashboard : Includes working interaction visualizations
|
|
98
|
+
compute_shap_interactions : Compute pairwise feature interactions
|
|
99
|
+
extract_interaction_viz_data : Extract structured data for custom dashboards
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
def __init__(
|
|
103
|
+
self,
|
|
104
|
+
title: str = "Feature Interaction Analysis",
|
|
105
|
+
theme: Literal["light", "dark"] = "light",
|
|
106
|
+
width: int | None = None,
|
|
107
|
+
height: int | None = None,
|
|
108
|
+
min_interaction_strength: float = 0.1,
|
|
109
|
+
):
|
|
110
|
+
"""Initialize Feature Interaction Dashboard.
|
|
111
|
+
|
|
112
|
+
Parameters
|
|
113
|
+
----------
|
|
114
|
+
title : str, default="Feature Interaction Analysis"
|
|
115
|
+
Dashboard title
|
|
116
|
+
theme : {'light', 'dark'}, default='light'
|
|
117
|
+
Visual theme
|
|
118
|
+
width : int, optional
|
|
119
|
+
Dashboard width in pixels
|
|
120
|
+
height : int, optional
|
|
121
|
+
Dashboard height in pixels
|
|
122
|
+
min_interaction_strength : float, default=0.1
|
|
123
|
+
Minimum interaction strength to display in network view
|
|
124
|
+
"""
|
|
125
|
+
super().__init__(title, theme, width, height)
|
|
126
|
+
self.min_interaction_strength = min_interaction_strength
|
|
127
|
+
|
|
128
|
+
def generate(
|
|
129
|
+
self,
|
|
130
|
+
analysis_results: dict[str, Any],
|
|
131
|
+
importance_results: dict[str, Any] | None = None,
|
|
132
|
+
**_kwargs,
|
|
133
|
+
) -> str:
|
|
134
|
+
"""Generate complete dashboard HTML.
|
|
135
|
+
|
|
136
|
+
Parameters
|
|
137
|
+
----------
|
|
138
|
+
analysis_results : dict
|
|
139
|
+
Results from compute_shap_interactions()
|
|
140
|
+
importance_results : dict, optional
|
|
141
|
+
Results from analyze_ml_importance() for cross-referencing
|
|
142
|
+
**kwargs
|
|
143
|
+
Additional parameters (currently unused)
|
|
144
|
+
|
|
145
|
+
Returns
|
|
146
|
+
-------
|
|
147
|
+
str
|
|
148
|
+
Complete HTML document
|
|
149
|
+
"""
|
|
150
|
+
# Extract structured data
|
|
151
|
+
viz_data = extract_interaction_viz_data(
|
|
152
|
+
analysis_results, importance_results=importance_results
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
# Create sections
|
|
156
|
+
self._create_network_section(viz_data)
|
|
157
|
+
self._create_matrix_section(viz_data)
|
|
158
|
+
self._create_per_feature_section(viz_data)
|
|
159
|
+
self._create_insights_section(viz_data)
|
|
160
|
+
|
|
161
|
+
# Compose HTML
|
|
162
|
+
return self._compose_html()
|
|
163
|
+
|
|
164
|
+
def _create_network_section(self, _viz_data: InteractionVizData) -> None:
|
|
165
|
+
"""Create network graph section."""
|
|
166
|
+
# Placeholder: Network visualization not implemented in v1.0
|
|
167
|
+
section = DashboardSection(
|
|
168
|
+
title="Network View",
|
|
169
|
+
description="Interactive network graph showing feature interactions",
|
|
170
|
+
content="<p>Network section - to be implemented</p>",
|
|
171
|
+
)
|
|
172
|
+
self.sections.append(section)
|
|
173
|
+
|
|
174
|
+
def _create_matrix_section(self, _viz_data: InteractionVizData) -> None:
|
|
175
|
+
"""Create interaction matrix heatmap section."""
|
|
176
|
+
# Placeholder: Matrix heatmap not implemented in v1.0
|
|
177
|
+
section = DashboardSection(
|
|
178
|
+
title="Matrix View",
|
|
179
|
+
description="Heatmap of all pairwise feature interactions",
|
|
180
|
+
content="<p>Matrix section - to be implemented</p>",
|
|
181
|
+
)
|
|
182
|
+
self.sections.append(section)
|
|
183
|
+
|
|
184
|
+
def _create_per_feature_section(self, _viz_data: InteractionVizData) -> None:
|
|
185
|
+
"""Create per-feature drill-down section."""
|
|
186
|
+
# Placeholder: Per-feature views not implemented in v1.0
|
|
187
|
+
section = DashboardSection(
|
|
188
|
+
title="Per-Feature Analysis",
|
|
189
|
+
description="Detailed interaction analysis for each feature",
|
|
190
|
+
content="<p>Per-feature section - to be implemented</p>",
|
|
191
|
+
)
|
|
192
|
+
self.sections.append(section)
|
|
193
|
+
|
|
194
|
+
def _create_insights_section(self, viz_data: InteractionVizData) -> None:
|
|
195
|
+
"""Create insights and recommendations section."""
|
|
196
|
+
llm_context = viz_data["llm_context"]
|
|
197
|
+
|
|
198
|
+
insights_html = f"""
|
|
199
|
+
<div class="insights-panel">
|
|
200
|
+
<h3>Summary</h3>
|
|
201
|
+
<p>{llm_context["summary_narrative"]}</p>
|
|
202
|
+
</div>
|
|
203
|
+
|
|
204
|
+
<div class="insights-panel">
|
|
205
|
+
<h3>Key Insights</h3>
|
|
206
|
+
<ul>
|
|
207
|
+
{"".join(f"<li>{insight}</li>" for insight in llm_context["key_insights"])}
|
|
208
|
+
</ul>
|
|
209
|
+
</div>
|
|
210
|
+
|
|
211
|
+
<div class="insights-panel">
|
|
212
|
+
<h3>Recommendations</h3>
|
|
213
|
+
<ul>
|
|
214
|
+
{"".join(f"<li>{rec}</li>" for rec in llm_context["recommendations"])}
|
|
215
|
+
</ul>
|
|
216
|
+
</div>
|
|
217
|
+
|
|
218
|
+
{
|
|
219
|
+
f'''
|
|
220
|
+
<div class="insights-panel">
|
|
221
|
+
<h3>Important Notes</h3>
|
|
222
|
+
<ul>
|
|
223
|
+
{"".join(f"<li>{caveat}</li>" for caveat in llm_context["caveats"])}
|
|
224
|
+
</ul>
|
|
225
|
+
</div>
|
|
226
|
+
'''
|
|
227
|
+
if llm_context["caveats"]
|
|
228
|
+
else ""
|
|
229
|
+
}
|
|
230
|
+
"""
|
|
231
|
+
|
|
232
|
+
section = DashboardSection(
|
|
233
|
+
title="Insights & Recommendations",
|
|
234
|
+
description="Auto-generated interpretation and actionable recommendations",
|
|
235
|
+
content=insights_html,
|
|
236
|
+
)
|
|
237
|
+
self.sections.append(section)
|
|
238
|
+
|
|
239
|
+
def _compose_html(self) -> str:
|
|
240
|
+
"""Compose final HTML document."""
|
|
241
|
+
return f"""
|
|
242
|
+
<!DOCTYPE html>
|
|
243
|
+
<html>
|
|
244
|
+
<head>
|
|
245
|
+
<meta charset="utf-8">
|
|
246
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
247
|
+
<title>{self.title}</title>
|
|
248
|
+
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
|
|
249
|
+
{self._get_base_styles()}
|
|
250
|
+
</head>
|
|
251
|
+
<body>
|
|
252
|
+
{self._build_header()}
|
|
253
|
+
{self._build_navigation()}
|
|
254
|
+
<div class="dashboard-container">
|
|
255
|
+
{self._build_sections()}
|
|
256
|
+
</div>
|
|
257
|
+
{self._get_base_scripts()}
|
|
258
|
+
</body>
|
|
259
|
+
</html>
|
|
260
|
+
"""
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
__all__ = ["FeatureInteractionDashboard"]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Interactive dashboard components for rich visualization.
|
|
2
|
+
|
|
3
|
+
This module re-exports all classes from the dashboards package
|
|
4
|
+
for backward compatibility.
|
|
5
|
+
|
|
6
|
+
Architecture:
|
|
7
|
+
- BaseDashboard: Abstract base class defining dashboard interface
|
|
8
|
+
- FeatureImportanceDashboard: Multi-tab importance analysis
|
|
9
|
+
- FeatureInteractionDashboard: Network and matrix interaction views (scaffold)
|
|
10
|
+
- ModelPerformanceDashboard: Prediction/error analysis (future)
|
|
11
|
+
- BacktestDashboard: Portfolio results analysis (future)
|
|
12
|
+
|
|
13
|
+
Design Principles:
|
|
14
|
+
- Progressive disclosure: Summary → Detail → Deep-dive
|
|
15
|
+
- Modular composition: Dashboards work standalone or compose
|
|
16
|
+
- Interactive controls: Tabs, dropdowns, filters, drill-down
|
|
17
|
+
- LLM-ready: Structured data enables future interpretation
|
|
18
|
+
- Professional output: Publication-quality HTML with embedded JS
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
# Re-export everything from the decomposed package
|
|
24
|
+
from ml4t.diagnostic.visualization.dashboards import (
|
|
25
|
+
THEMES,
|
|
26
|
+
BaseDashboard,
|
|
27
|
+
DashboardSection,
|
|
28
|
+
FeatureImportanceDashboard,
|
|
29
|
+
FeatureInteractionDashboard,
|
|
30
|
+
get_theme,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
__all__ = [
|
|
34
|
+
# Theme utilities
|
|
35
|
+
"THEMES",
|
|
36
|
+
"get_theme",
|
|
37
|
+
# Base classes
|
|
38
|
+
"BaseDashboard",
|
|
39
|
+
"DashboardSection",
|
|
40
|
+
# Dashboard implementations
|
|
41
|
+
"FeatureImportanceDashboard",
|
|
42
|
+
"FeatureInteractionDashboard",
|
|
43
|
+
]
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Enhanced data extraction for visualization layer.
|
|
2
|
+
|
|
3
|
+
This module provides comprehensive data extraction from analysis results,
|
|
4
|
+
exposing all details needed for rich interactive dashboards, including:
|
|
5
|
+
- Per-method breakdowns with uncertainty
|
|
6
|
+
- Per-feature aggregations for drill-down views
|
|
7
|
+
- Method comparison metrics
|
|
8
|
+
- Auto-generated narratives for LLM consumption
|
|
9
|
+
|
|
10
|
+
The extracted data is structured for both human visualization and LLM interpretation.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from .importance import extract_importance_viz_data
|
|
14
|
+
from .interaction import extract_interaction_viz_data
|
|
15
|
+
from .types import (
|
|
16
|
+
FeatureDetailData,
|
|
17
|
+
FeatureInteractionData,
|
|
18
|
+
ImportanceVizData,
|
|
19
|
+
InteractionMatrixData,
|
|
20
|
+
InteractionVizData,
|
|
21
|
+
LLMContextData,
|
|
22
|
+
MethodComparisonData,
|
|
23
|
+
MethodImportanceData,
|
|
24
|
+
NetworkGraphData,
|
|
25
|
+
UncertaintyData,
|
|
26
|
+
)
|
|
27
|
+
from .validation import _validate_lengths_match, _validate_matrix_feature_alignment
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
# Main extraction functions
|
|
31
|
+
"extract_importance_viz_data",
|
|
32
|
+
"extract_interaction_viz_data",
|
|
33
|
+
# TypedDict types for importance
|
|
34
|
+
"ImportanceVizData",
|
|
35
|
+
"MethodImportanceData",
|
|
36
|
+
"FeatureDetailData",
|
|
37
|
+
"MethodComparisonData",
|
|
38
|
+
"UncertaintyData",
|
|
39
|
+
"LLMContextData",
|
|
40
|
+
# TypedDict types for interaction
|
|
41
|
+
"InteractionVizData",
|
|
42
|
+
"FeatureInteractionData",
|
|
43
|
+
"NetworkGraphData",
|
|
44
|
+
"InteractionMatrixData",
|
|
45
|
+
# Validation helpers (for internal use)
|
|
46
|
+
"_validate_lengths_match",
|
|
47
|
+
"_validate_matrix_feature_alignment",
|
|
48
|
+
]
|