跳到主要內容
AI News HubLIVE
來源內容 · 翻譯待補全4 分鐘閱讀

待翻譯:End-to-End Bayesian Marketing Mix Modeling with Google Meridian: Media Measurement, ROI Analysis, and Budget Optimization

文章摘要

AI 服務暫時不可用,以下為來源摘要,待恢復後補全翻譯:In this tutorial, we build a complete Bayesian marketing mix modeling workflow using Google Meridian. We begin by installing the required libraries, verifying GPU availability, and exploring a geo-level marketing dataset that includes media impressions, spend, controls, promotions, conversions, population, and revenue. We then map the raw columns to Meridian’s data schema, define interpretable ROI-based […] The post End-to-End Bayesian Marketing Mix Modeling with Google Meridian: Media Measurement, ROI Analysis, and Budget Optimization appeared first on MarkTechPost.

來源MarkTechPost作者: Sana Hassan
待翻譯:End-to-End Bayesian Marketing Mix Modeling with Google Meridian: Media Measurement, ROI Analysis, and Budget Optimization
報告錯誤

更正渠道尚未開通,可先複製下方文章資訊留存。

查看更正說明
直接讀正文

AI 服務暫時不可用,以下為來源正文,待恢復後補全翻譯。

In this tutorial, we build a complete Bayesian marketing mix modeling workflow using Google Meridian. We begin by installing the required libraries, verifying GPU availability, and exploring a geo-level marketing dataset that includes media impressions, spend, controls, promotions, conversions, population, and revenue. We then map the raw columns to Meridian’s data schema, define interpretable ROI-based priors, and configure the model before fitting it with prior and posterior NUTS sampling. After training, we evaluate convergence and predictive accuracy, examine channel contributions, ROI, marginal ROI, effectiveness, adstock, saturation, and response curves, and use the Analyzer API to extract custom posterior metrics. We conclude the workflow by optimizing both fixed and flexible budgets, generating shareable HTML reports, and saving the fitted model for reuse. Copy CodeCopiedUse a different Browser !pip install --upgrade -q "google-meridian[and-cuda]" import numpy as np import pandas as pd import altair as alt import tensorflow as tf import tensorflow_probability as tfp from IPython.display import display, HTML from meridian import constants from meridian.data import load from meridian.model import model from meridian.model import spec from meridian.model import prior_distribution from meridian.analysis import analyzer from meridian.analysis import visualizer from meridian.analysis import optimizer from meridian.analysis import summarizer def show(chart_or_obj, title=None): if title: display(HTML(f" {title} ")) display(chart_or_obj) print("TensorFlow:", tf.version) gpus = tf.config.experimental.list_physical_devices("GPU") print("GPUs detected:", gpus if gpus else "NONE — sampling will be slow on CPU!") CSV_URL = ( "https://raw.githubusercontent.com/google/meridian/refs/heads/main/" "meridian/data/simulated_data/csv/geo_all_channels.csv" ) df = pd.read_csv(CSV_URL) print("\nShape:", df.shape) print("Geos:", df["geo"].nunique(), "| Weeks:", df["time"].nunique()) print("Date range:", df["time"].min(), "->", df["time"].max()) display(df.head()) spend_cols = [c for c in df.columns if c.endswith("_spend")] spend_share = df[spend_cols].sum().rename("total_spend").reset_index() spend_share["share_%"] = 100 * spend_share["total_spend"] / spend_share["total_spend"].sum() display(spend_share) kpi_by_week = df.groupby("time")["conversions"].sum().reset_index() show( alt.Chart(kpi_by_week).mark_line().encode( x=alt.X("time:T", title="Week"), y=alt.Y("conversions:Q", title="Total conversions (all geos)"), ).properties(width=700, height=250), "National KPI over time", ) We install Google Meridian with GPU-enabled TensorFlow support and import the libraries required for modeling, visualization, and analysis. We verify the runtime environment, detect available GPUs, and load Meridian’s simulated geo-level marketing dataset. We also perform initial exploratory analysis by reviewing data dimensions, date coverage, spend distribution, and national conversion trends. Copy CodeCopiedUse a different Browser coord_to_columns = load.CoordToColumns( time="time", geo="geo", controls=["competitor_sales_control", "sentiment_score_control"], population="population", kpi="conversions", revenue_per_kpi="revenue_per_conversion", media=[ "Channel0_impression", "Channel1_impression", "Channel2_impression", "Channel3_impression", "Channel4_impression", ], media_spend=[ "Channel0_spend", "Channel1_spend", "Channel2_spend", "Channel3_spend", "Channel4_spend", ], organic_media=["Organic_channel0_impression"], non_media_treatments=["Promo"], ) media_to_channel = {f"Channel{i}_impression": f"Channel_{i}" for i in range(5)} media_spend_to_channel = {f"Channel{i}_spend": f"Channel_{i}" for i in range(5)} loader = load.CsvDataLoader( csv_path=CSV_URL, kpi_type="non_revenue", coord_to_columns=coord_to_columns, media_to_channel=media_to_channel, media_spend_to_channel=media_spend_to_channel, ) data = loader.load() print("\nInputData loaded. Media tensor shape (geo, time, channel):", data.media.shape) roi_mu = 0.2 roi_sigma = 0.9 prior = prior_distribution.PriorDistribution( roi_m=tfp.distributions.LogNormal(roi_mu, roi_sigma, name=constants.ROI_M) ) model_spec = spec.ModelSpec(prior=prior) mmm = model.Meridian(input_data=data, model_spec=model_spec) We map the raw dataset columns to Meridian’s expected schema using CoordToColumns. We define paid media, spend, organic channels, controls, treatments, population, KPI, and revenue-related fields before loading the structured input data. We then configure ROI-based priors, create the model specification, and initialize the Meridian model. Copy CodeCopiedUse a different Browser mmm.sample_prior(500) mmm.sample_posterior( n_chains=7, n_adapt=500, n_burnin=500, n_keep=1000, seed=1, ) print("Sampling complete.") model_diagnostics = visualizer.ModelDiagnostics(mmm) show(model_diagnostics.plot_rhat_boxplot(), "R-hat convergence check (want roi_np[..., 0]).mean() print(f"P(ROI Channel_1 > ROI Channel_0) = {p_better:.1%}") summary_metrics = analysis.summary_metrics() print("\nsummary_metrics() xarray variables:", list(summary_metrics.data_vars)) inc_outcome = np.asarray(analysis.incremental_outcome()) print("Incremental outcome draws shape (chains, draws, channels):", inc_outcome.shape) We examine channel response curves, adstock decay, and Hill saturation behavior to understand diminishing returns and carryover effects. We use the Analyzer API to extract posterior ROI draws and calculate channel-level means and credible intervals. We also compute probabilistic channel comparisons, inspect summary metrics, and retrieve incremental outcome estimates. Copy CodeCopiedUse a different Browser budget_optimizer = optimizer.BudgetOptimizer(mmm) optimization_results = budget_optimizer.optimize() show(optimization_results.plot_budget_allocation(), "Optimized budget allocation") show(optimization_results.plot_spend_delta(), "Recommended spend change per channel") show(optimization_results.plot_incremental_outcome_delta(), "Incremental outcome gained by reallocating") show(optimization_results.plot_response_curves(), "Response curves with current vs. optimal spend points") flexible_results = budget_optimizer.optimize( fixed_budget=False, target_roi=1.5, ) show(flexible_results.plot_budget_allocation(), "Flexible-budget allocation at target ROI = 1.5") mmm_summarizer = summarizer.Summarizer(mmm) mmm_summarizer.output_model_results_summary( "model_results_summary.html", "/content", "2021-01-25", "2024-01-15" ) optimization_results.output_optimization_summary( "budget_optimization_summary.html", "/content" ) print("Reports written to /content/model_results_summary.html " "and /content/budget_optimization_summary.html") save_path = "/content/saved_mmm.pkl" model.save_mmm(mmm, save_path) mmm_reloaded = model.load_mmm(save_path) print("Model saved and reloaded from", save_path) roi_reloaded = np.asarray(analyzer.Analyzer(mmm_reloaded).roi()).mean(axis=(0, 1)) print("Reloaded ROI means:", np.round(roi_reloaded, 3)) print("\n" + "=" * 70) print("TUTORIAL COMPLETE ") print("Next steps with YOUR data:") print(" 1. Replace CSV_URL and CoordToColumns with your columns.") print(" 2. Calibrate per-channel ROI priors with experiment results.") print(" 3. Check R-hat < 1.05 before trusting any output.") print(" 4. Use holdout_id in ModelSpec for out-of-sample validation.") print("=" * 70) We optimize marketing spend under both fixed-budget and target-ROI scenarios. We visualize recommended allocations, spend changes, expected outcome gains, and optimized positions on response curves. We then generate HTML reports, save and reload the fitted model, and verify that the restored model reproduces the same ROI estimates. In conclusion, we developed an end-to-end framework for measuring media performance and translating Bayesian model estimates into practical marketing decisions. We validated the model using convergence diagnostics and predictive metrics before interpreting channel-level results, helping us avoid relying on unstable or misleading estimates. We assessed each channel using contribution, ROI, marginal ROI, effectiveness, carryover, and saturation, and used posterior draws to quantify uncertainty and compare channels probabilistically. We then converted these insights into optimized budget allocations under fixed-budget and target-ROI scenarios. Finally, we exported the results and persisted the fitted model, allowing us to repeat analysis, test new scenarios, and adapt the workflow to real business data without rerunning the most computationally expensive steps. Check out the FULL CODES here. Also, feel free to follow us on Twitter and don’t forget to join our 150k+ML SubReddit and Subscribe to our Newsletter. Wait! are you on telegram? now you can join us on telegram as well. Need to partner with us for promoting your GitHub Repo OR Hugging Face Page OR Product Release OR Webinar etc.? Connect with us The post End-to-End Bayesian Marketing Mix Modeling with Google Meridian: Media Measurement, ROI Analysis, and Budget Optimization appeared first on MarkTechPost.

展開要點與分析

文章情報

工程師進階

要點

  • AI 服務暫時不可用,系統已先保留來源內容與降級元數據。
  • In this tutorial, we build a complete Bayesian marketing mix modeling workflow using Google Meridian. We begin by installing the required libraries, verifying GPU availability, an…

技術影響

可能影響 GPU、推理集羣、算力成本和供應鏈規劃。

要點與分析由自動化流程生成,可能有誤,請結合原始來源核實。