运行模型
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
运行模型时,您需要添加模型规范,然后运行命令,对先验分布和后验分布进行抽样。
模型采用了马尔可夫链蒙特卡洛 (MCMC) 算法从后验分布中抽样。Meridian 使用 No-U-Turn 抽样方法,此方法可以自适应调整步长和核。
如要运行模型,请执行以下操作:
添加模型规范。
示例:
model_spec = spec.ModelSpec(
prior=prior_distribution.PriorDistribution(),
media_effects_dist='log_normal',
hill_before_adstock=False,
max_lag=8,
unique_sigma_for_each_geo=False,
media_prior_type='roi',
roi_calibration_period=None,
rf_prior_type='coefficient',
rf_roi_calibration_period=None,
organic_media_prior_type='contribution',
organic_rf_prior_type='contribution',
non_media_treatments_prior_type='contribution',
knots=None,
baseline_geo=None,
holdout_id=None,
control_population_scaling_id=None,
)
运行以下命令,从先验分布和后验分布中进行抽样。根据需要配置形参:
meridian = model.Meridian(input_data=data, model_spec=model_spec)
meridian.sample_prior(500)
meridian.sample_posterior(n_chains=7, n_adapt=500, n_burnin=500, n_keep=1000)
形参 |
说明 |
n_chains |
要并行抽样的链数量。为了减少内存消耗,您可以使用一个整数列表,按顺序进行 MCMC 抽样调用。如果使用列表,序列中的每个元素都对应一个 n_chains 实参,用以调用 windowed_adaptive_nuts 。 |
n_adapt |
每条链上在步长和核调整期间进行的 MCMC 抽样次数。这些抽样结果始终会被排除在最终样本之外。 |
n_burnin |
在确定步长和核后,每条链上要额外排除的 MCMC 抽样次数。这些额外的抽样可能是为了确保所有链在完成自适应调整后都能达到稳定分布状态,但在实际应用中,我们通常会发现这些链在自适应调整期间就能达到稳定分布状态,因此 n_burnin=0 就够了。 |
n_keep |
每条链上要保留的 MCMC 抽样次数,抽取的样本将用于模型分析和生成结果。 |
接下来,运行建模诊断以评估收敛性、查看分布和评估模型拟合度。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-06-17。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-06-17。"],[[["The model requires a defined model specification, which includes parameters like prior distribution, media effects, and other configurations."],["To run the model, you first define the model specification and then use the `meridian` object to sample from both the prior and posterior distributions."],["Markov Chain Monte Carlo (MCMC) methods are used for sampling from the posterior distribution, utilizing the No-U-Turn sampling method with step size and kernel adaptation."],["Parameters like `n_chains`, `n_adapt`, `n_burnin`, and `n_keep` control the MCMC sampling process, determining the number of parallel chains, adaptation draws, burn-in draws, and draws to keep."]]],["The process involves specifying a model using `ModelSpec`, defining parameters like prior distributions, media effects, and lag. Then, use the `Meridian` class to run the model by sampling from prior and posterior distributions. The posterior sampling employs the No-U-Turn algorithm with step size and kernel adaptation, and requires parameter configuration like `n_chains`, `n_adapt`, `n_burnin`, and `n_keep` to control the Markov Chain Monte Carlo draws. After sampling, you run model diagnostics to assess the quality of the results.\n"]]