日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

概率编程库Pymc3案例之鲁棒线性回归

發(fā)布時(shí)間:2025/4/16 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 概率编程库Pymc3案例之鲁棒线性回归 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

參考:https://twiecki.io/blog/2013/08/27/bayesian-glms-2/

https://twiecki.io/blog/2014/03/17/bayesian-glms-3/

https://twiecki.github.com/blog/2013/08/12/bayesian-glms-1/

針對(duì)線性回歸中異常點(diǎn),利用t分布來(lái)替換正態(tài)分布構(gòu)建貝葉斯模型。

%matplotlib inline import pymc3 as pm import matplotlib.pyplot as plt import numpy as np import theano size = 100 true_intercept = 1 true_slope = 2x = np.linspace(0, 1, size) # y = a + b*x true_regression_line = true_intercept + true_slope * x # add noise y = true_regression_line + np.random.normal(scale=.5, size=size) # Add outliers x_out = np.append(x, [.1, .15, .2]) y_out = np.append(y, [8, 6, 9]) data = dict(x=x_out, y=y_out) fig = plt.figure(figsize=(12, 12)) ax = fig.add_subplot(111, xlabel='x', ylabel='y', title='Generated data and underlying model') ax.plot(x_out, y_out, 'x', label='sampled data') ax.plot(x, true_regression_line, label='true regression line', lw=2.) plt.legend(loc=0);

with pm.Model() as model_robust:family = pm.glm.families.StudentT()pm.GLM.from_formula('y ~ x', data, family=family)trace_robust = pm.sample(progressbar=False, tune=1000)plt.figure(figsize=(12, 12)) plt.plot(x_out, y_out, 'x') pm.plots.plot_posterior_predictive_glm(trace_robust,label='posterior predictive regression lines') plt.plot(x, true_regression_line, label='true regression line', lw=3., c='y') plt.legend(); Auto-assigning NUTS sampler... Initializing NUTS using jitter+adapt_diag... Multiprocess sampling (4 chains in 4 jobs) NUTS: [lam, x, Intercept]

PyMC3's?glm()?function allows you to pass in a?family?object that contains information about the likelihood.

  • By changing the likelihood from a Normal distribution to a Student T distribution -- which has more mass in the tails -- we can perform?Robust Regression.

總結(jié)

以上是生活随笔為你收集整理的概率编程库Pymc3案例之鲁棒线性回归的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。