您的位置:首页 > 汽车 > 新车 > 建模杂谈系列250 Hello2Pymc

建模杂谈系列250 Hello2Pymc

2024/10/6 20:35:25 来源:https://blog.csdn.net/yukai08008/article/details/141728079  浏览:    关键词:建模杂谈系列250 Hello2Pymc

说明

pymc算是多年的老朋友了,中间失联了好几年。

内容

1 安装

安装更加麻烦了,不能很好的和其他的环境兼容。在官网上,也是建议用conda的方式安装。
在这里插入图片描述

conda create -c conda-forge -n pymc_env "pymc>=5"
conda activate pymc_env

2 测试

import arviz as az
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pymc as pm
import xarray as xrfrom pymc import HalfCauchy, Model, Normal, sampleprint(f"Running on PyMC v{pm.__version__}")Running on PyMC v5.16.2

跑跑看

with Model() as model:  # model specifications in PyMC are wrapped in a with-statement# Define priorssigma = HalfCauchy("sigma", beta=10)intercept = Normal("Intercept", 0, sigma=20)slope = Normal("slope", 0, sigma=20)# Define likelihoodlikelihood = Normal("y", mu=intercept + slope * x, sigma=sigma, observed=y)# Inference!# draw 3000 posterior samples using NUTS samplingidata = sample(3000)Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [sigma, Intercept, slope]
Sampling 4 chains, 0 divergences ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00 / 0:00:05
Sampling 4 chains for 1_000 tune and 3_000 draw iterations (4_000 + 12_000 draws total) took 6 seconds.

这样应该是可以了

3 资料

  • Installation
  • gallery
  • books

在这里插入图片描述
在这里插入图片描述

先这些吧,后面还有很多事需要做才能完全捡起来。

这块算是一条通往近似计算、贝叶斯推断的一条路,是更好的机器学习方法。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com