加入新推出的
Discord 社区,展开实时讨论,获得同行支持,并直接与 Meridian 团队互动!
meridian.analysis.visualizer.ModelDiagnostics
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
根据 Meridian 模型拟合生成模型诊断图表。
meridian.analysis.visualizer.ModelDiagnostics(
meridian: meridian.model.model.Meridian
)
方法
plot_prior_and_posterior_distribution
查看源代码
plot_prior_and_posterior_distribution(
parameter: str = 'roi_m',
num_geos: int = 3,
selected_times: (list[str] | None) = None
) -> (alt.Chart | alt.FacetChart)
为模型形参绘制先验分布和后验分布。
实参 |
parameter
|
要绘制的模型形参名称。默认情况下,如果未指定名称,系统会显示投资回报率形参。
|
num_geos
|
在地理位置级形参图表中显示的最大地理位置(按人口计算)的数量。默认情况下,系统仅显示前三大地理位置。
|
selected_times
|
要为时间级形参绘制的特定时间段的列表。这些时间必须与数据中的时间段相匹配。默认情况下,系统会绘制前三个时间段。
|
可能引发的错误 |
NotFittedModelError
|
模型尚未拟合。
|
ValueError
|
parameter 不是 Meridian 模型形参。
|
plot_rhat_boxplot
查看源代码
plot_rhat_boxplot() -> alt.Chart
绘制 R-hat 箱线图。
关于链收敛的 Gelman 和 Rubin(1992 年)潜在规模缩减(通常称为 R-hat)的直观摘要。这是一种收敛诊断衡量,用于衡量链间(平均值)方差超出链同分布时预期方差的程度。值接近 1.0 表示收敛。R-hat 值小于 1.2 表示近似收敛,对于许多问题来说,这是一个合理阈值(Brooks 和 Gelman,1998 年)。
每个模型形参都有一个 R-hat 值。该箱线图总结了各个索引中 R-hat 值的分布情况。例如,与 beta_gm
对应的箱线图汇总了地理位置索引 g
和渠道索引 m
中 R-hat 值的分布情况。
系统没有对任何具有确定性先验的形参定义 R-hat,因此这些形参不会显示在箱线图上。
参考 |
Andrew Gelman 和 Donald B. Rubin。Inference from Iterative Simulation Using Multiple Sequences,Statistical Science,7(4):457-472,1992 年。Stephen P. Brooks 和 Andrew Gelman。General Methods for Monitoring Convergence of Iterative Simulations
|
返回结果 |
显示每个形参的 R-hat 箱线图的 Altair 图表。
|
可能引发的错误 |
NotFittedModelError
|
模型尚未拟合。
|
MCMCSamplingError
|
MCMC 抽样未收敛。
|
predictive_accuracy_table
查看源代码
predictive_accuracy_table(
selected_geos: (Sequence[str] | None) = None,
selected_times: (Sequence[str] | None) = None,
column_var: (str | None) = None,
batch_size: int = c.DEFAULT_BATCH_SIZE
) -> pd.DataFrame
显示 DataFrame 的预测准确率。
实参 |
selected_geos
|
可选列表,包含要纳入的一部分地理位置维度。默认纳入所有地理位置。这些地理位置应与 meridian.InputData 中的地理位置维度名称相匹配。设置 selected_geos 或 n_top_largest_geos ,请勿同时设置两者。
|
selected_times
|
可选列表,包含要纳入的一部分时间维度。
默认纳入所有时间。这些时间必须与 meridian.InputData 中的时间维度相匹配。
|
column_var
|
可选字符串,用于指明是按 metric 、geo_granularity 还是 evaluation_set 对表进行透视。默认情况下,column_var=None 表示在返回的非透视 DataFrame 中显示 metric 、geo_granularity 和 value 列(holdout_id 不为 None 时,还会显示 evaluation_set )。 |
batch_size
|
整数,表示每个批次中每条链的最大抽样次数。计算分批次运行,以避免内存耗尽。如果发生内存错误,可以试着减小 batch_size 。一般而言,batch_size 值越大,计算速度越快。
|
返回结果 |
包含计算出的 R_Squared 、MAPE 和 wMAPE 值的 DataFrame。如果存在 holdout_id ,数据将被拆分为 Train 、Test 和 All Data 子部分,而 evaluation_set 将作为列包含在从数据集到 DataFrame 的转换中。
|
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-01-25。
[null,null,["最后更新时间 (UTC):2025-01-25。"],[],["The `ModelDiagnostics` class generates plots and tables for model analysis. Key actions include: plotting prior and posterior distributions of model parameters, allowing selection of specific parameters, geographies, and time periods. It also generates an R-hat box plot to assess chain convergence, indicating values close to 1.0 are desirable. Additionally, it provides a table displaying predictive accuracy using metrics like R-squared, MAPE, and wMAPE, with options to filter by geographies and time periods.\n"],null,[]]