加入新推出的
Discord 社区,展开实时讨论,获得同行支持,并直接与 Meridian 团队互动!
评估模型拟合度和结果
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
营销组合建模分析 (MMM) 的主要目标是准确估计营销工作的因果效应。不过,直接验证因果推理的质量非常困难,需要精心设计的实验。这些实验必须正确开展,而且必须具有与 MMM 相同的被估量。由于您使用的是 MMM,因此实验很可能不切实际。鉴于此,您无法直接评估因果推理,而是必须依赖间接衡量方式。
我们的建议是,您制定的建模决策应符合因果推理的目标,而不是为了最大限度地减少预测误差。请考虑以下准则:
确保您的控制变量集包含对媒体执行和响应都有影响的所有重要混杂变量。如需了解详情,请参阅选择控制变量。
谨慎纳入实际上并非混杂因素的控制变量。变量过多可能会增加出现过拟合和模型误设造成偏差的风险。
只添加您有兴趣了解因果推理的媒体变量。
根据为模型中的时间效应选择结数内的建议建立时间模型,不一定要使用尽可能多的结来建立时间模型。
此过程确实需要您从广告客户的角度进行一些自我反思,不过这样做有助于确保模型拟合度达到最佳。考虑到您自己规划了媒体策略,您可能知道或清楚哪些变量会影响您的媒体执行规划。
结果必须合理。不合理的结果包括基准过低(通常为负值,请参阅评估基准),或者一个媒体渠道主导所有其他媒体渠道。Meridian 具有样本外预测性指标,可用作初步检查,以确保模型结构适当且未过度形参化。
样本外预测性指标简介
营销组合建模分析 (MMM) 的目标是因果推理,而不一定是最小化样本外预测性指标。可以建立一个包含所有混杂变量的模型,并允许模型结构有足够的灵活性,以获得无偏见的因果估计值(例如投资回报率);即使这意味着模型是过拟合的,但这种做法安全性更高。
最好还是检查一下样本外拟合度,以确保模型结构合适且没有过度形参化,但样本外预测性指标不应该是评估模型拟合度的主要方式。可以使用 ModelSpec
中的 holdout_id
实参以及 Analyzer
的 predictive_accuracy
方法来评估样本外拟合度。
获取所有形参的后验分布抽样
您可以通过 inference_data
属性从 Meridian 模型对象获取所有形参的后验分布抽样。
例如,若要从名为 mmm
的 Meridian 模型对象获取每个媒体渠道的 alpha(Adstock 衰减形参)后验值,您可以获取属性 mmm.inference_data.posterior.alpha_m
。从这里,您可以使用类似于这个例子(针对的是第 75 百分位数)的语法从后验分布中获取任何百分位数:
np.percentile(meridian.inference_data.posterior.alpha_m, 0.75, axis=(0, 1))
您还可以计算投资回报率至少为 1 的后验概率:
(meridian.inference_data.posterior.roi_m >= 1).mean(dim=('chain', 'draw'))
此外,您还可以为形参的估计后验分布获取集中趋势以及指定宽度的可信区间。例如,您可以使用以下语法获取 alpha_m
的均值和第 90 百分位的可信区间:
Analyzer.get_central_tendency_and_ci(mmm.inference_data.posterior.alpha_m, 0.9)
所有其他形参的后验分布也可以通过类似的方式获取。
模型拟合的方法及结果
Analyzer
类有几种方法可以提供许多相关的后建模量。
部分示例如下:
Analyzer.media_summary_metrics
提供按渠道分类的汇总表。相关指标包括:impressions
、spend
、incremental_outcome
、pct_of_contribution
、ROI
、effectiveness
和 mROI
。
Analyzer.incremental_outcome
用于了解特定媒体来源的结果。
Analyzer.roi
可估计投资回报率,并可按媒体、时间和地理位置进行自定义。
Analyzer.marginal_roi
可估计边际投资回报率,并可按媒体、时间和地理位置进行自定义。
Analyzer.response_curves
会返回绘制响应曲线时使用的数据。
Analyzer.predictive_accuracy
会返回预测准确性指标,包括 R 平方、MAPE、wMAPE。
Analyzer.expected_outcome
会返回先验或后验预期结果。
如需查看方法的完整列表以及有关其潜在规范的更多信息(包括如何选择特定地理位置或时间),请参阅 analyzer.py 代码。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-04。
[null,null,["最后更新时间 (UTC):2025-08-04。"],[[["\u003cp\u003eMarketing mix modeling (MMM) focuses on estimating causal marketing effects, but direct validation is challenging, requiring reliance on indirect measures and informed modeling decisions.\u003c/p\u003e\n"],["\u003cp\u003ePrioritize modeling choices that support causal inference over minimizing prediction error, such as carefully selecting control variables and focusing on relevant media variables.\u003c/p\u003e\n"],["\u003cp\u003eEvaluate model results for reasonableness, ensuring they align with expectations and avoid unrealistic outcomes like negative baselines or single-channel dominance.\u003c/p\u003e\n"],["\u003cp\u003eWhile out-of-sample prediction metrics offer a preliminary check, they shouldn't be the primary model fit assessment; causal inference remains the central goal.\u003c/p\u003e\n"],["\u003cp\u003eAccess posterior distribution draws and utilize Analyzer methods to gain insights into model parameters, media impact, ROI, and other key performance indicators.\u003c/p\u003e\n"]]],[],null,["# Assess the model fit and the results\n\nThe primary goal of marketing mix modeling (MMM) is the accurate estimation of\ncausal marketing effects. However, directly validating the quality of causal\ninference is difficult and requires well-designed experiments. These\nexperiments must be executed correctly and must have the same estimand as the\nMMM. Since you are using an MMM, experiments are likely not practical. For\nthis reason, the causal inference cannot be directly assessed. Instead, you\nhave to rely on indirect measures.\n\nWe recommend that you make modeling decisions that make sense for the goal of\ncausal inference, and not for minimizing prediction error. Consider these\nguidelines:\n\n- Make sure that your control variable set includes all important confounding\n variables, which impact both media execution and the response. For more\n information, see [Selecting control variables](/meridian/docs/advanced-modeling/control-variables#selecting-control-variables).\n\n- Be careful about including control variables that are not actually\n confounders. Too many variables can increase the risk of overfitting and\n model misspecification bias.\n\n- Only add media variables for which you are interested in learning the causal\n inference.\n\n- Model time using the advice in [Choosing the number of knots for time effects in the model](/meridian/docs/advanced-modeling/setting-knots#choosing-number-of-knots-time-effects),\n and don't necessarily try to model time with as many knots as you can.\n\nThis process does require some self-reflection from you as the advertiser,\nhowever this will most likely lead to the best model fit. Considering that you\nplanned your own media strategy, you probably know or have a strong sense of\nwhat variables impacted your planning around media execution.\n\nThe [results](#access-results) need to make sense. Results that don't make sense\ninclude unusually low baselines that are often negative (see\n[Assess the baseline](/meridian/docs/advanced-modeling/baseline)) or one media\nchannel dominating all other media channels. Meridian has\n[out-of-sample prediction metrics](/meridian/docs/advanced-modeling/model-fit#out-of-sample-metrics)\nwhich are useful as a preliminary check to make sure the model structure is\nappropriate and not extremely overparameterized.\n\nAbout out-of-sample prediction metrics\n--------------------------------------\n\nThe goal in marketing mix modeling (MMM) is causal inference, and not\nnecessarily to minimize out-of-sample prediction metrics. It can be safer to\nhave a model that includes all confounding variables and allows enough\nflexibility in the model structure to get unbiased, causal estimates (such as\nROI), even if this means the model is overfit.\n\nIt is still a good idea to check the out-of-sample fit to make sure your model\nstructure is appropriate and not extremely overparameterized, but the\nout-of-sample prediction metrics shouldn't be the primary way model fit is\nassessed. Out-of-sample fit can be evaluated using the `holdout_id`\nargument in `ModelSpec` and the `predictive_accuracy` method of `Analyzer`.\n\nAccess the posterior distribution draws for all parameters\n----------------------------------------------------------\n\nThe posterior distribution draws of all parameters can be accessed from the\nMeridian model object through the `inference_data` attribute.\n\nFor example, to access values of the posterior for alpha (Adstock decay\nparameter) for each media channel from a Meridian model object named\n`mmm` you can access the property `mmm.inference_data.posterior.alpha_m`. From\nthere you can obtain any percentile from the posterior distribution using syntax\nsimilar to this example for a 75th percentile: \n\n np.percentile(meridian.inference_data.posterior.alpha_m, 0.75, axis=(0, 1))\n\nYou can also calculate the posterior probability of ROI being at least 1: \n\n (meridian.inference_data.posterior.roi_m \u003e= 1).mean(dim=('chain', 'draw'))\n\nAdditionally, you can obtain the central tendency and credible interval of\nspecified width for the estimated posterior distribution of a parameter. For\nexample, the mean and 90th percentile credible interval for `alpha_m`can be\nobtained using the following syntax: \n\n Analyzer.get_central_tendency_and_ci(mmm.inference_data.posterior.alpha_m, 0.9)\n\nThe posterior distributions for all other parameters can be accessed in a\nsimilar manner.\n\nMethods for model fit and results\n---------------------------------\n\nThe `Analyzer` class has several methods providing many of the post-modeling\nquantities of interest.\n\nSome examples include:\n\n- `Analyzer.media_summary_metrics` provides a summary table organized by channel. The metrics of interest include: `impressions`, `spend`, `incremental_outcome`, `pct_of_contribution`, `ROI`, `effectiveness`, and `mROI`.\n- `Analyzer.incremental_outcome` lets you explore the outcome of a specific media source.\n- `Analyzer.roi` provides estimates of ROI and can be customized by media, time, and geo.\n- `Analyzer.marginal_roi` provides estimates of marginal ROI and can be customized by media, time, and geo.\n- `Analyzer.response_curves` returns the data used in plotting the response curves.\n- `Analyzer.predictive_accuracy` returns metrics for predictive accuracy, including R-squared, MAPE, wMAPE.\n- `Analyzer.expected_outcome` returns either the prior or posterior expected outcome.\n\nFor a full list of methods and more information about their potential\nspecifications, including selecting specific geos or times, see the\n[analyzer.py](/meridian/reference/api/meridian/analysis/analyzer) code."]]