Loading [MathJax]/jax/input/TeX/jax.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Google 因果推断的CausalImpact 贝叶斯结构时间序列模型(二十二)

Google 因果推断的CausalImpact 贝叶斯结构时间序列模型(二十二)

作者头像
悟乙己
发布于 2021-12-31 01:03:09
发布于 2021-12-31 01:03:09
1.9K00
代码可运行
举报
文章被收录于专栏:素质云笔记素质云笔记
运行总次数:0
代码可运行

之前一篇:跟着开源项目学因果推断——CausalImpact 贝叶斯结构时间序列模型(二十一)

这里另外写一篇来继续研究一下CausalImpact这个开源库的一些细节的

1 CausalImpact 一些可调参数

1.1 CausalImpact默认的两种算法

CausalImpact默认使用TensorFlow Probability来求的两种算法,分别是Variational InferenceHamiltonian Monte Carlo

切换的方式:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# HMC
ci = CausalImpact(data, pre_period, post_period, model_args={'fit_method': 'hmc'})

# VI
ci = CausalImpact(data, pre_period, post_period, model_args={'fit_method': 'vi'})

1.2 model_args的可调节模型参数

CausalImpact中,model_args还可以做几种修改:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
standardize: bool
   If `True`, standardizes data to have zero mean and unitary standard
   deviation.
prior_level_sd: Optional[float]
   Prior value for the local level standard deviation. If `None` then an
   automatic optimization of the local level is performed. This is
   recommended when there's uncertainty about what prior value is
   appropriate for the data.
   In general, if the covariates are expected to be good descriptors of the
   observed response then this value can be low (such as the default of
   0.01). In cases when the linear regression is not quite expected to fully
   explain the observed data, the value 0.1 can be used.
fit_method: str
   Which method to use for the Bayesian algorithm. Can be either 'vi'
   (default) or 'hmc' (more precision but much slower).
nseasons: int
 Specifies the duration of the period of the seasonal component; if input
 data is specified in terms of days, then choosing nseasons=7 adds a weekly
 seasonal effect.
season_duration: int
 Specifies how many data points each value in season spans over. A good
 example to understand this argument is to consider a hourly data as input.
 For modeling a weekly season on this data, one can specify `nseasons=7` and
 season_duration=24 which means each value that builds the season component
 is repeated for 24 data points. Default value is 1 which means the season
 component spans over just 1 point (this in practice doesn't change
 anything). If this value is specified and bigger than 1 then `nseasons`
 must be specified and bigger than 1 as well.

其中,

  • standardize = True,需要给入的数据就是标准化过的;
  • nseasons: int,如果想by week来看影响,可以设置为:
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
ci = CausalImpact(data, pre_period, post_period,nseasons=[{'period': 7}],trend=True)
  • prior_level_sd,设定先验标准差
  • season_duration: int,这个要与nseasons联合来看

举一个例子,比如我们现在有by hour的数据,然后我们希望By week来看效果,那么需要设定为:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
df = pd.DataFrame('tests/fixtures/arma_data.csv')
df = df.set_index(pd.date_range(start='20200101', periods=len(data), freq='H'))
pre_period = ['20200101 00:00:00', '20200311 23:00:00']
post_period = ['20200312 00:00:00', '20200410 23:00:00']
ci = CausalImpact(df, pre_period, post_period, model_args={'nseasons': 7,   'season_duration': 24})
print(ci.summary())

这里可以这么理解,如果是Hour粒度数据需要By week看,那就需要每隔 7*24个数据点作为一个batch,所以这里就是nseasons * season_duration

1.3 CausalImpact自定义模型

如果除了提供的VI / HMC都不满足,自己可以自定义:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
      import tensorflow_probability as tfp


      pre_y = data[:70, 0]
      pre_X = data[:70, 1:]
      obs_series = data.iloc[:, 0]
      local_linear = tfp.sts.LocalLinearTrend(observed_time_series=obs_series)
      seasonal = tfp.sts.Seasonal(nseasons=7, observed_time_series=obs_series)
      model = tfp.sts.Sum([local_linear, seasonal], observed_time_series=obs_series)

      ci = CausalImpact(data, pre_period, post_period, model=model)
      print(ci.summary())

分别在3.7.4 和 2.3的案例中都会采用自定义

1.4 CausalImpact如何数据标准化

来看一个来自[test_main.py ],数据是官方项目里面的数据,例子:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import numpy as np
import pandas as pd
import pytest
import tensorflow as tf
import tensorflow_probability as tfp
from numpy.testing import assert_array_equal
from pandas.util.testing import assert_frame_equal

from causalimpact import CausalImpact
from causalimpact.misc import standardize

data = pd.read_csv('tests/fixtures/btc.csv', parse_dates=True, index_col='Date')
training_start = "2020-12-01"
training_end = "2021-02-05"
treatment_start = "2021-02-08"
treatment_end = "2021-02-09"
pre_period = [training_start, training_end]
post_period = [treatment_start, treatment_end]

pre_data = rand_data.loc[pre_int_period[0]: pre_int_period[1], :]
# 标准化
normed_pre_data, (mu, sig) = standardize(pre_data)
# mu / sig如何让原数据post_data  ->  标准化之后的normed_post_data 

normed_post_data = (post_data - mu) / sig

使用causalimpact.misc进行标准化; 如果你自行标准化之后,在训练模型的时候,需要:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
model_args == {'fit_method': 'hmc', 'niter': 1000, 'prior_level_sd': 0.01,  'season_duration': 1, 'nseasons': 1, 'standardize': True}

2 协变量回归系数解读

在整个模型中会有:

yt=ZTtαt+βXt+Gtϵt

其中线性部分,拆出来单独理解

2.1 Horseshoe prior的Bayes回归

来自统计之都的一篇文章先认识一下Horseshoe prior: 使用Horseshoe 先验的Bayes回归及代码解析 以及: 稀疏数据分析:马蹄估计量及其理论性质

也贴一段,tensorflow_probability感觉写的很好:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  The Cauchy scale parameters puts substantial mass near zero, encouraging
  weights to be sparse, but their heavy tails allow weights far from zero to be
  estimated without excessive shrinkage. The horseshoe can be thought of as a
  continuous relaxation of a traditional 'spike-and-slab' discrete sparsity
  prior, in which the latent Cauchy scale mixes between 'spike'
  (`scales[i] ~= 0`) and 'slab' (`scales[i] >> 0`) regimes.
  Following the recommendations in [2], `SparseLinearRegression` implements
  a horseshoe with the following adaptations:
  - The Cauchy prior on `scales[i]` is represented as an InverseGamma-Normal
    compound.
  - The `global_scale` parameter is integrated out following a `Cauchy(0.,
    scale=weights_prior_scale)` hyperprior, which is also represented as an
    InverseGamma-Normal compound.
  - All compound distributions are implemented using a non-centered
    parameterization.
  The compound, non-centered representation defines the same marginal prior as
  the original horseshoe (up to integrating out the global scale),
  but allows samplers to mix more efficiently through the heavy tails; for
  variational inference, the compound representation implicity expands the
  representational power of the variational model.
  Note that we do not yet implement the regularized ('Finnish') horseshoe,
  proposed in [2] for models with weak likelihoods, because the likelihood
  in STS models is typically Gaussian, where it's not clear that additional
  regularization is appropriate. If you need this functionality, please
  email tfprobability@tensorflow.org.

Horseshoe prior是一种稀疏bayes监督学习的方法。通过对模型参数的先验分布中加入稀疏特征,从而得到稀疏的估计。

horseshoe prior属于multivariate scale mixtures of normals的分布族。所以和其他常用的稀疏bayes学习方法,Laplacian prior, (Lasso), Student-t prior,非常类似。

其中λj 叫做local shrinkage parameter,局部压缩参数,对于不同的θj 可以有不同的压缩系数,τ 叫做global shrinkage parameter其中,half-Cauchy分布的概率密度函数:

回看上面三层先验,上面a 就可以带入各自的先验:

考虑λi 的边缘先验分布

定义κi=1/(1+λ2i) 这个量在Bayesian shrinkage中非常重要,我们在下一个小标题介绍它的意义,但我们可以先分析它的先验分布。现在我们只想做一点定性分析,了解一下κi 的先验的形状,所以简单起见假设σ=τ=1 ,于是

因此 kiBeta(1/2,1/2) ,来看ki 的先验分布,这里可以看到a =β =0.5的时候,就会出现马蹄状,基于这种先验的贝叶斯方法被称为马蹄估计。

这里有一段tensorflow_probability 中的评价:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
The Cauchy scale parameters puts substantial mass near zero, encouraging   weights to be sparse, but their heavy tails allow weights far from zero to be   estimated without excessive shrinkage.
The horseshoe can be thought of as a   continuous relaxation of a traditional 'spike-and-slab' discrete sparsity   prior, in which the latent Cauchy scale mixes between 'spike'   (`scales[i] ~= 0`) and 'slab' (`scales[i] >> 0`) regimes.

2.2 SparseLinearRegression的weight计算逻辑

因为在CausalImpact 会使用SparseLinearRegression,我来看一下回归部分的系数weight求解,参考下面公式:

来到tensorflow_probability的源代码中看到:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
This is identical to `tfp.sts.LinearRegression`, except that   `SparseLinearRegression` uses a parameterization of a Horseshoe prior [1][2] to encode the assumption that many of the `weights` are zero,  i.e., many of the covariate time series are irrelevant.

可以看到local scales 是服从HalfCauchy分布:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
scales[i] ~ HalfCauchy(loc=0, scale=1)
weights[i] ~ Normal(loc=0., scale=scales[i] * global_scale)`

由伪代码来看整个回归系数计算过程:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# Sample global_scale from Cauchy(0, scale=weights_prior_scale).
global_scale_variance ~ InverseGamma(alpha=0.5, beta=0.5)
global_scale_noncentered ~ HalfNormal(loc=0, scale=1)
global_scale = (global_scale_noncentered *
               sqrt(global_scale_variance) *
               weights_prior_scale)
# Sample local_scales from Cauchy(0, 1).
local_scale_variances[i] ~ InverseGamma(alpha=0.5, beta=0.5)
local_scales_noncentered[i] ~ HalfNormal(loc=0, scale=1)
local_scales[i] = local_scales_noncentered[i] * sqrt(local_scale_variances[i])
weights[i] ~ Normal(loc=0., scale=local_scales[i] * global_scale)

weights[i] ~ Normal(loc=0., scale=local_scales[i] * global_scale)开始反着看,weight = local的λj 和 global的τ 的相乘。

2.3 案例推导回归系数的计算

如果默认VI算法的情况下:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import numpy as np
import pandas as pd
import pytest
import tensorflow as tf
import tensorflow_probability as tfp
from numpy.testing import assert_array_equal
from pandas.util.testing import assert_frame_equal

from causalimpact import CausalImpact
from causalimpact.misc import standardize

data = pd.read_csv('../tests/fixtures/btc.csv', parse_dates=True, index_col='Date')
training_start = "2020-12-01"
training_end = "2021-02-05"
treatment_start = "2021-02-08"
treatment_end = "2021-02-09"
pre_period = [training_start, training_end]
post_period = [treatment_start, treatment_end]


rand_data = data
pre_int_period = pre_period
post_int_period = post_period
ci = CausalImpact(rand_data, pre_int_period, post_int_period)


for name, values in ci.model_samples.items():
    print(f'{name}: {values.numpy().mean(axis=0)}')

本来官方教程里面默认算法下的一些标准差为:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
print('Mean value of noise observation std: ', ci.model_samples[0].numpy().mean())
print('Mean value of level std: ', ci.model_samples[1].numpy().mean())
print('Mean value of linear regression x0, x1: ', ci.model_samples[2].numpy().mean(axis=0))

可以看到三个比较明显的指标,noise std,level std,回归系数。 那么现在的版本,可以看到ci.model_samples是一个dict形,然后得出有,

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
observation_noise_scale: 0.455566942691803
LocalLevel/_level_scale: 0.01129493024200201
SparseLinearRegression/_global_scale_variance: 0.8674567341804504
SparseLinearRegression/_global_scale_noncentered: 0.9352844953536987
SparseLinearRegression/_local_scale_variances: [1.4979423  1.3915676  2.5401886  0.82398146 1.3655316  1.3455669
 1.2680935  0.9430675  2.4824152 ]
SparseLinearRegression/_local_scales_noncentered: [0.6454335  1.1153866  1.5575289  0.39585915 0.85925627 0.964816
 0.7337909  0.7373393  1.4985642 ]
SparseLinearRegression/_weights_noncentered: [-0.31404912  1.3935399   1.904644   -0.769298    0.7848593   0.53083557
  0.9080193   0.37757748  1.6231401 ]

observation_noise_scaleLocalLevel/_level_scale 与之前一样,这里LR改成了,特有的SparseLinearRegression

再返回CausalImpact 的输出结果:

  • causalimpact 的issue
  • tensorflow_probability

先来看tensorflow_probability 的源码,可以从Line298开始看:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  def params_to_weights(
                        global_scale_variance,
                        global_scale_noncentered,
                        local_scale_variances,
                        local_scales_noncentered,
                        weights_noncentered,
  weights_prior_scale = 0.1):
    """Build regression weights from model parameters."""
    global_scale = (global_scale_noncentered *
                    tf.sqrt(global_scale_variance) *
                    weights_prior_scale)

    local_scales = local_scales_noncentered * tf.sqrt(local_scale_variances)
    return weights_noncentered * local_scales * global_scale[..., tf.newaxis]

其中weights_prior_scaleThe weights_prior_scale determines the level of sparsity; small scales encourage the weights to be sparse. 是先验分布的参数,决定稀疏程度,一般默认为0.1

再来看一下weight输出的结果,是weights.shape == [num_users, num_features],不像之前

再是causalimpact 的issue,参考 : Printing averages of the posterior does not work #24

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import tensorflow as tf


weights_prior_scale = 0.1
global_scale_nonentered = param_samples['SparseLinearRegression/_global_scale_noncentered']
global_scale_variance = param_samples['SparseLinearRegression/_global_scale_variance']
local_scales_noncentered = param_samples['SparseLinearRegression/_local_scales_noncentered']
local_scale_variances = param_samples['SparseLinearRegression/_local_scale_variances']
global_scale = global_scale_nonentered * tf.sqrt(global_scale_variance) * weights_prior_scale
weights_noncented = param_samples['SparseLinearRegression/_weights_noncentered']
local_scales = local_scales_noncentered * tf.sqrt(local_scale_variances)

weights = weights_noncented * local_scales * global_scale[..., tf.newaxis]

# 按样本的权重,100个
weights.numpy().mean(axis=1)

# 按特征的权重 ,2个
weights.numpy().mean(axis=0)

# 所有的平均权重,1个
weights.numpy().mean(axis=1).mean()

如果有了weight,那如何进行预测,可以简单看一下预测的逻辑:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
predicted_timeseries = self.design_matrix.matmul(weights[..., tf.newaxis])
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021/12/29 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
跟着开源项目学因果推断——CausalImpact 贝叶斯结构时间序列模型(二十一)
非随机化的效果评估方法(二) 一图讲清因果推断方法论,无法 AB 测试时分析的万能钥匙
悟乙己
2021/12/24
4.1K0
跟着开源项目学因果推断——CausalImpact 贝叶斯结构时间序列模型(二十一)
干货 | 贝叶斯结构模型在全量营销效果评估的应用
如何科学地推断某个产品策略对观测指标产生的效应非常重要,这能够帮助产品和运营更精准地得到该策略的价值,从而进行后续方向的迭代及调整。
携程技术
2023/09/18
1.6K0
干货 | 贝叶斯结构模型在全量营销效果评估的应用
资源 | 概率编程工具:TensorFlow Probability官方简介
选自Medium 作者:Josh Dillon、Mike Shwe、Dustin Tran 机器之心编译 参与:白妤昕、李泽南 在 2018 年 TensorFlow 开发者峰会上,谷歌发布了 TensorFlow Probability,这是一个概率编程工具包,机器学习研究人员和从业人员可以使用它快速可靠地构建最先进、复杂的硬件模型。 TensorFlow Probability 适用于以下需求: 希望建立一个生成数据模型,推理其隐藏进程。 需要量化预测中的不确定性,而不是预测单个值。 训练集具有大量相对
机器之心
2018/05/08
1.6K0
资源 | 概率编程工具:TensorFlow Probability官方简介
干货 | TensorFlow Probability 概率编程入门级实操教程
之前没有学过概率编程?对 TensorFlow Probability(TFP)还不熟悉?下面我们为你准备了入门级实操性教程——《Bayesian Methods for Hackers》(教程查看地址:https://camdavidsonpilon.github.io/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/#tensorflow),这门教程的实例现在也在 TFP 中开放了。作为对所有人开放的开源资源,TFP 版本的概率编程对之前用 PyMC3 写的那版进行了补充。
AI科技评论
2019/10/31
1.2K0
干货 | TensorFlow Probability 概率编程入门级实操教程
TensorFlow团队:TensorFlow Probability的简单介绍
在2018年TensorFlow开发者峰会上,我们(TensorFlow团队)宣布发布TensorFlow Probability:一种使机器学习研究人员及相关从业人员可以快速可靠地利用最先进硬件构建复杂模型的概率编程工具箱。TensorFlow Probability适用的情况包括:
AiTechYun
2018/07/27
2.3K0
TensorFlow团队:TensorFlow Probability的简单介绍
Google Earth Engine——Landsat图像在描述全球森林范围和变化方面的时间序列分析结果(2014年)
Results from time-series analysis of Landsat images in characterizing global forest extent and change.
此星光明
2024/02/02
1510
Google Earth Engine——Landsat图像在描述全球森林范围和变化方面的时间序列分析结果(2014年)
教程 | 概率编程:使用贝叶斯神经网络预测金融市场价格
选自Medium 作者:Alex Honchar 机器之心编译 参与:陈韵竹、李泽南 随着人工智能技术的普及,用机器学习预测市场价格波动的方法最近层出不穷。本文中,Alex Honchar 介绍了利用概率编程和 Pyro 进行价格预测的方法,相较于常规神经网络,新方法对于数据的依赖程度更小,结果更准确。在实验中,作者选择了最近流行的虚拟货币「以太币」作为实例进行价格预测。 去年我曾发表过几篇有关使用神经网络进行金融价格预测的教程,我认为其中有一部分结果至少还挺有意思,并且值得在实际交易中加以应用。如果你阅读
机器之心
2018/05/10
2.1K0
Tensorflow实现朴素贝叶斯分类器
朴素贝叶斯分类器是基于贝叶斯定理以及一些有关特征独立性的强(朴素)假设的简单概率分类器,也称“独立特征模型”。本文demo使用TF的实现朴素贝叶斯分类器,用TensorFlow_probability概率库实现参数可训练的高斯分布变种。
flavorfan
2021/02/27
1.6K1
Tensorflow实现朴素贝叶斯分类器
【论文推荐】最新6篇主题模型相关论文—正则化变分推断主题模型、非参数先验、在线聊天、词义消歧、神经语言模型
【导读】专知内容组整理了最近六篇主题模型(Topic Modeling)相关文章,为大家进行介绍,欢迎查看! 1. Topic Modeling on Health Journals with Regularized Variational Inference(基于正则化变分推断主题模型的健康杂志分析) ---- ---- 作者:Robert Giaquinto,Arindam Banerjee 摘要:Topic modeling enables exploration and compact repre
WZEARW
2018/04/12
7770
【论文推荐】最新6篇主题模型相关论文—正则化变分推断主题模型、非参数先验、在线聊天、词义消歧、神经语言模型
一切模型皆可联邦化:高斯朴素贝叶斯代码示例
联邦学习是一种分布式的机器学习方法,其中多个客户端在一个中央服务器的协调下合作训练模型,但不共享他们的本地数据。一般情况下我们对联邦学习的理解都是大模型和深度学习模型才可以进行联邦学习,其实基本上只要包含参数的机器学习方法都可以使用联邦学习的方法保证数据隐私。
deephub
2024/06/17
1900
一切模型皆可联邦化:高斯朴素贝叶斯代码示例
【前沿】NIPS2017贝叶斯生成对抗网络TensorFlow实现(附GAN资料下载)
导读 今年五月份康奈尔大学的 Andrew Gordon Wilson 和 Permutation Venture 的 Yunus Saatchi 提出了一个贝叶斯生成对抗网络(Bayesian GAN),结合贝叶斯和对抗生成网络,提出了一个实用的贝叶斯公式框架,用GAN来进行无监督学习和半监督式学习。论文《Bayesian GAN》也被2017年机器学习顶级会议 NIPS 接受,今天Andrew Gordon Wilson在Twitter上发布消息开源了这篇论文的TensorFlow实现,并且Google
WZEARW
2018/04/10
1.5K0
【前沿】NIPS2017贝叶斯生成对抗网络TensorFlow实现(附GAN资料下载)
【高能】用PyMC3进行贝叶斯统计分析(代码+实例)
问题类型1:参数估计 真实值是否等于X? 给出数据,对于参数,可能的值的概率分布是多少? 例子1:抛硬币问题 硬币扔了n次,正面朝上是h次。 参数问题 想知道 p 的可能性。给定 n 扔的次数和 h 正面朝上次数,p 的值很可能接近 0.5,比如说在 [0.48,0.52]? 说明 参数的先验信念:p∼Uniform(0,1) 似然函数:data∼Bernoulli(p) import pymc3 as pmimport numpy.random as nprimport numpy as
量化投资与机器学习微信公众号
2018/01/30
4.4K0
【高能】用PyMC3进行贝叶斯统计分析(代码+实例)
【机器学习-监督学习】朴素贝叶斯
  贝叶斯分类是一类分类算法的总称,这类算法均以贝叶斯定理为基础,所以统称为贝叶斯分类。朴素贝叶斯是一种贝叶斯分类算法,在许多场合可以与决策树和神经网络分类算法相媲美。图1展示了贝叶斯原理、贝叶斯分类和朴素贝叶斯三者之间的关系。
Francek Chen
2025/01/22
2050
【机器学习-监督学习】朴素贝叶斯
5篇生成模型相关 paper
Bayesian GAN Yunus Saatchi Andrew Gordon Wilson
CreateAMind
2018/07/24
3990
5篇生成模型相关 paper
贝叶斯深度学习——基于PyMC3的变分推理
原文链接:Bayesian Deep Learning (http://twiecki.github.io/blog/2016/06/01/bayesian-deep-learning/) 作者:Thomas Wiecki,关注贝叶斯模型与Python 译者:刘翔宇 校对:赵屹华 责编:周建丁(zhoujd@csdn.net) 目前机器学习的发展趋势 目前机器学习有三大趋势:概率编程、深度学习和“大数据”。在概率编程(PP)方面,有许多创新,它们大规模使用变分推理。在这篇博客中,我将展示如何使用Py
用户1737318
2018/06/06
5.4K0
因果推断与反事实预测——利用DML进行价格弹性计算(二十四)
经济学课程里谈到价格需求弹性,描述需求数量随商品价格的变动而变化的弹性。价格一般不直接影响需求,而是被用户决策相关的中间变量所中介作用。假设 Q 为某个商品的需求的数量,P 为该商品的价格,则计算需求的价格弹性为,
悟乙己
2022/05/09
4K0
因果推断与反事实预测——利用DML进行价格弹性计算(二十四)
统计学学术速递[7.26]
【1】 Joint Shapley values: a measure of joint feature importance 标题:关节Shapley值:关节特征重要性的度量
公众号-arXiv每日学术速递
2021/07/27
7350
使用python进行贝叶斯统计分析|附代码数据
本文讲解了使用PyMC3进行基本的贝叶斯统计分析过程. ( 点击文末“阅读原文”获取完整代码数据******** )。
拓端
2023/08/02
3410
时间序列预测与递归神经网络在Keras的应用基于Python
编辑整理 编辑部:西西 原文作者 Jason Brownlee 问题描述 问题为:国际客运量预测。该数据范围从 1949 年 1 月至 1960 年 12 月。 下面是一个样本的文件 但是我们感兴趣的不是日期 , 因为每个被观察的相同间距隔开的一个月。因此,我们可以排除加载数据集的第一列。 你可以看到数据集有一个上升趋势的。你还可以看到一些周期性等。 长短期记忆网络 The Long Short-Term Memory network, or LSTM network, is a recur
量化投资与机器学习微信公众号
2018/01/29
1.1K0
时间序列预测与递归神经网络在Keras的应用基于Python
使用python手写Metropolis-Hastings算法的贝叶斯线性回归
在学习贝叶斯计算的解马尔可夫链蒙特卡洛(MCMC)模拟时,最简单的方法是使用PyMC3,构建模型,调用Metropolis优化器。但是使用别人的包我们并不真正理解发生了什么,所以本文通过手写Metropolis-Hastings来深入的理解MCMC的过程,再次强调我们自己实现该方法并不是并不是为了造轮子,而是为了更好的通过代码理解该概念。
deephub
2022/11/11
6930
使用python手写Metropolis-Hastings算法的贝叶斯线性回归
推荐阅读
相关推荐
跟着开源项目学因果推断——CausalImpact 贝叶斯结构时间序列模型(二十一)
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档