src.driver.base

V2 driver orchestrator using composition pattern.

This module provides the MMMBaseDriverV2 class which delegates to specialized component classes for clean separation of concerns.

Module Contents

class src.driver.base.MMMBaseDriverV2(config_filename: str, input_filename: str, holidays_filename: str, results_filename: str = 'results', results_folder_creation_time: datetime.datetime | None = None, model: src.core.base.BaseMMM | None = None, run_id: str | datetime.datetime | None = None)

V2 driver class for orchestrating the MMM workflow.

Uses composition pattern to delegate functionality to specialized component classes. This provides better separation of concerns and easier testing while maintaining the same public API.

Uses the model architecture with in-graph scaling to prevent tensor shape contamination when running models with different channel configurations sequentially.

init_output(data_dir: str = '.') str

Initialises and creates the output directory for results.

create_downloadable_zip(excluded_files: List[str], source_folder: str = '/content', zip_name: str = 'Model_files.zip') None

Creates a downloadable zip file, excluding specified files. Colab-specific.

run_feature_engineering() src.prepro.input_data.InputData

Placeholder for feature engineering steps. Currently a no-op.

describe_data(input_data_raw: src.prepro.input_data.InputData, input_data_processed: src.prepro.input_data.InputData, current_commit: str) None

Generates descriptive outputs for raw and processed data.

main() str | None

Main execution workflow for the V2 MMM driver.

fit_model(model_filename: str | None = None) src.core.base.BaseMMM

Fits a marketing model using provided data and configuration.

visualize() None

Visualises the results of the model.

describe_all_media_spend() Any

Describes overall media spend.

plot_all_media_spend() Any

Plots overall media spend.

plot_model_structure() graphviz.Digraph

Plots the model structure.

plot_model_trace() matplotlib.figure.Figure

Plots the trace of the model parameters.

plot_components_contributions() matplotlib.figure.Figure

Plots the contribution of each model component over time.

plot_posterior_predictions() matplotlib.figure.Figure

Plots the in-sample and out-of-sample posterior predictions.

plot_waterfall_components_decomposition(model_to_plot: src.core.base.BaseMMM | None = None, original_scale: bool = True, figsize: Tuple[int, int] = (14, 7), **kwargs: Any) matplotlib.figure.Figure

Plots the waterfall decomposition of the model components.

plot_posterior_distributions(results_dir_override: str | None = None, filename_prefix: str = 'media_spend_posterior') pandas.DataFrame | None

Plots posterior distributions for all media channels.

display_image(image_filename: str) Any | None

Displays an image file located in the results directory.

predict_on_test() numpy.ndarray | Any

Generates posterior predictive samples using the test dataset.

calculate_train_r_squared() float

Calculates the R-squared value of the model on the training set.

plot_posterior_predictive() matplotlib.figure.Figure

Generates and plots posterior predictive samples.