Module: schema.processors.marketing_processor

Meridian module for analyzing marketing data in a Meridian model.

This module provides a MarketingProcessor , designed to extract key marketing insights from a trained Meridian model. It allows users to understand the impact of different marketing channels, calculate return on investment (ROI), and generate response curves.

The processor uses specifications defined in MarketingAnalysisSpec to control the analysis. Users can request:

  1. Media Summary Metrics:Aggregated performance metrics for each media channel, including spend, contribution, ROI, and effectiveness.
  2. Incremental Outcomes:The additional KPI or revenue driven by marketing activities, calculated by comparing against a baseline scenario (e.g., zero spend).
  3. Response Curves:Visualizations of how the predicted KPI or revenue changes as spend on a particular channel increases, helping to identify diminishing returns.

The results are output as a MarketingAnalysisList protobuf message, containing detailed breakdowns per channel and for the baseline.

Key Classes:

  • MediaSummarySpec : Configures the calculation of summary metrics like ROI.
  • IncrementalOutcomeSpec : Configures the calculation of incremental impact.
  • ResponseCurveSpec : Configures response curve generation.
  • MarketingAnalysisSpec : The main specification to combine the above, define date ranges, and set confidence levels.
  • MarketingProcessor : The processor class that executes the analysis based on the provided specs.

Example Usage:

  1. Get Media Summary Metrics for a specific period:

      from 
      
     schema.processors 
      
     import 
     marketing_processor 
     import 
      
     datetime 
     # Assuming 'trained_model' is a loaded Meridian model object 
     spec 
     = 
     marketing_processor 
     . 
     MarketingAnalysisSpec 
     ( 
     analysis_name 
     = 
     "q1_summary" 
     , 
     start_date 
     = 
     datetime 
     . 
     date 
     ( 
     2023 
     , 
     1 
     , 
     1 
     ), 
     end_date 
     = 
     datetime 
     . 
     date 
     ( 
     2023 
     , 
     3 
     , 
     31 
     ), 
     media_summary_spec 
     = 
     marketing_processor 
     . 
     MediaSummarySpec 
     ( 
     aggregate_times 
     = 
     True 
     ), 
     response_curve_spec 
     = 
     marketing_processor 
     . 
     ResponseCurveSpec 
     (), 
     confidence_level 
     = 
     0.9 
     , 
     ) 
     processor 
     = 
     marketing_processor 
     . 
     MarketingProcessor 
     ( 
     trained_model 
     ) 
     # `result` is a `marketing_analysis_pb2.MarketingAnalysisList` proto 
     result 
     = 
     processor 
     . 
     execute 
     ([ 
     spec 
     ]) 
     
    
  2. Calculate Incremental Outcome with new spend data:

      from 
      
     schema.processors 
      
     import 
     marketing_processor 
     from 
      
     meridian.analysis 
      
     import 
     analyzer 
     import 
      
     datetime 
     import 
      
     numpy 
      
     as 
      
     np 
     # Assuming 'trained_model' is a loaded Meridian model object 
     # Assuming 'new_media_spend' is a numpy array with shape (time, channels) 
     # Create DataTensors for the new data 
     # Example: 
     # new_data = analyzer.DataTensors( 
     #     media=new_media_spend, 
     #     time=new_time_index, 
     # ) 
     spec 
     = 
     marketing_processor 
     . 
     MarketingAnalysisSpec 
     ( 
     analysis_name 
     = 
     "what_if_scenario" 
     , 
     # NOTE: Dates must align with `new_data.time` 
     start_date 
     = 
     datetime 
     . 
     date 
     ( 
     2023 
     , 
     1 
     , 
     1 
     ), 
     end_date 
     = 
     datetime 
     . 
     date 
     ( 
     2023 
     , 
     1 
     , 
     31 
     ), 
     incremental_outcome_spec 
     = 
     marketing_processor 
     . 
     IncrementalOutcomeSpec 
     ( 
     new_data 
     = 
     new_data 
     , 
     aggregate_times 
     = 
     True 
     , 
     ), 
     ) 
     processor 
     = 
     marketing_processor 
     . 
     MarketingProcessor 
     ( 
     trained_model 
     ) 
     result 
     = 
     processor 
     . 
     execute 
     ([ 
     spec 
     ]) 
     print 
     ( 
     f 
     "Incremental Outcome for 
     { 
     spec 
     . 
     analysis_name 
     } 
     :" 
     ) 
     # Process results from result.marketing_analyses 
     
    

Classes

class IncrementalOutcomeSpec : Stores parameters needed for processing a model into MarketingAnalysis s.

class MarketingAnalysisSpec : Stores parameters needed for processing a model into MarketingAnalysis s.

class MarketingProcessor : Generates MarketingAnalysis protos for a given trained Meridian model.

class MediaSummarySpec : Stores parameters needed for creating media summary metrics.

class ResponseCurveSpec : Stores parameters needed for creating response curves.

Design a Mobile Site
View Site in Mobile | Classic
Share by: