Analysis and Postprocessing
Comprehensive Analysis
Comprehensive post-processing analysis for DeepCausalMMM with inverse transformation. Includes all visualizations: coefficients, contributions, DAG, actual vs predicted, channel analysis. Automatically handles burn-in/padding removal from all outputs.
- class deepcausalmmm.postprocess.comprehensive_analysis.ComprehensiveAnalyzer(model, media_cols: List[str], control_cols: List[str], output_dir: str = 'mmm_analysis_results', pipeline=None, auto_detect_burnin: bool = True, manual_burnin_weeks: int | None = None, config: Dict | None = None, inference: InferenceManager | None = None)[source]
Bases:
objectModernized comprehensive analyzer for DeepCausalMMM with config-driven visualizations.
- __init__(model, media_cols: List[str], control_cols: List[str], output_dir: str = 'mmm_analysis_results', pipeline=None, auto_detect_burnin: bool = True, manual_burnin_weeks: int | None = None, config: Dict | None = None, inference: InferenceManager | None = None)[source]
Initialize the comprehensive analyzer.
- Parameters:
model – Trained DeepCausalMMM model
media_cols – List of media column names
control_cols – List of control column names
output_dir – Directory to save outputs
pipeline – UnifiedDataPipeline instance for modern data processing
auto_detect_burnin – Whether to automatically detect burn-in weeks from model
manual_burnin_weeks – Manually specify burn-in weeks (overrides auto-detection)
config – Configuration dictionary (uses default if None)
inference – Modern InferenceManager instance
- inverse_transform_target(y_scaled: ndarray) ndarray[source]
Apply inverse transformation to target variable using modern pipeline.
- Parameters:
y_scaled – Scaled target values
- Returns:
Unscaled target values
- inverse_transform_contributions(contributions_scaled: ndarray, y_original: ndarray) ndarray[source]
Apply inverse transformation to contributions using modern pipeline.
- Parameters:
contributions_scaled – Scaled contributions
y_original – Original scale target values
- Returns:
Contributions in original scale
- analyze_with_unified_pipeline(X_media: ndarray, X_control: ndarray, y_true: ndarray, create_plots: bool = True) Dict[str, Any][source]
Perform comprehensive analysis using the unified pipeline.
- Parameters:
X_media – Media data (full dataset)
X_control – Control data (full dataset)
y_true – True target values (full dataset)
create_plots – Whether to create visualization plots
- Returns:
Dictionary with analysis results
- analyze_comprehensive(X_media: ndarray, X_control: ndarray, y_true: ndarray, region_ids: ndarray, weeks: List[int] | None = None) Dict[str, Any][source]
Run comprehensive analysis with all visualizations. Automatically removes burn-in/padding from all outputs.
- Parameters:
X_media – Media variables [n_regions, n_weeks, n_channels] (may include padding)
X_control – Control variables [n_regions, n_weeks, n_controls] (may include padding)
y_true – True target values (scaled, may include padding)
region_ids – Region identifiers
weeks – Week labels (optional)
- Returns:
Dictionary containing all analysis results (burn-in removed)
Statistical Analysis
Post-processing utilities for analyzing and visualizing DeepCausalMMM results.
- class deepcausalmmm.postprocess.analysis.ModelAnalyzer(inference: InferenceManager | None = None, legacy_inference: ModelInference | None = None, scaler: SimpleGlobalScaler | None = None, pipeline=None, config: Dict | None = None, output_dir: str | None = None)[source]
Bases:
objectAnalyze and visualize DeepCausalMMM model results with modern class-based architecture.
- __init__(inference: InferenceManager | None = None, legacy_inference: ModelInference | None = None, scaler: SimpleGlobalScaler | None = None, pipeline=None, config: Dict | None = None, output_dir: str | None = None)[source]
Initialize the enhanced analyzer with unified pipeline support.
- Parameters:
inference – Modern InferenceManager instance (preferred)
legacy_inference – Legacy ModelInference instance (for compatibility)
scaler – SimpleGlobalScaler for proper inverse transformations (legacy)
pipeline – UnifiedDataPipeline instance (preferred)
config – Model configuration dictionary
output_dir – Directory to save outputs
- analyze_with_unified_pipeline(model, X_media: ndarray, X_control: ndarray, y_true: ndarray, channel_names: List[str], control_names: List[str]) Dict[str, Any][source]
Analyze model results using the unified pipeline.
- Parameters:
model – Trained model
X_media – Media data
X_control – Control data
y_true – True target values
channel_names – Media channel names
control_names – Control variable names
- Returns:
Analysis results dictionary
- analyze_predictions(X_m: ndarray, X_c: ndarray, R: ndarray, y_true: ndarray | None = None, generate_plots: bool = True) Dict[str, Any][source]
Analyze model predictions and generate visualizations.
- Parameters:
X_m – Media variables [n_regions, n_weeks, n_channels]
X_c – Control variables [n_regions, n_weeks, n_controls]
R – Region indices [n_regions] (reserved;
InferenceManagercurrently builds region indices internally)y_true – Optional ground truth values
generate_plots – Whether to generate and save plots
- Returns:
Dictionary containing analysis results and metrics
- static plot_coefficients_over_time(coefficients: ndarray, channel_names: List[str]) Figure[source]
Plot mean coefficients over time for each channel.
- static plot_contribution_comparison(predictions: ndarray, actuals: ndarray | None, burn_in_weeks: int) Figure[source]
Plot actual vs predicted revenue comparison.
DAG Postprocessing
Post-processing utilities for DAG visualization and analysis.
Deprecated since version 1.0.0: This module is deprecated and will be removed in v2.0.0. Please use the modern VisualizationManager class instead:
from deepcausalmmm.core.visualization import VisualizationManager
viz_manager = VisualizationManager(config) viz_manager.create_dag_network_plot(…) viz_manager.create_dag_heatmap_plot(…)
- deepcausalmmm.postprocess.dag_postprocess.plot_dag_structure(adjacency_matrix: Tensor, channel_names: List[str] | None = None, threshold: float = 0.1, title: str = 'Media Channel DAG Structure') Figure[source]
Deprecated since version 1.0.0: This function is deprecated. Use VisualizationManager.create_dag_network_plot() instead.