akaike_info_criterion_lsq#
- astropy.stats.akaike_info_criterion_lsq(ssr, n_params, n_samples)[源代码]#
假设观测值为高斯分布,计算Akaike信息准则。
在这种情况下,AIC表示为
\[\mathrm{AIC}=n\ln\左(\dfrac{\mathrm{SSR}}{n}\右)+2k\]如果样本量不够大,则进行校正,即。
\[\mathrm{AIC}=n\ln\左(\dfrac{\mathrm{SSR}}{n}\右)+2k+\]在哪儿 \(n\) 是样本量, \(k\) 是可用参数的数目,并且 \(\mathrm{{SSR}}\) 表示模型和数据之间残差平方和。
这是适用的,例如,当一个模型的参数估计使用最小二乘统计。
- 参数:
- 返回:
- aic :
float
Python :浮点 阿卡克信息准则。
- aic :
工具书类
[1]阿卡克信息准则。<https://en.wikipedia.org/wiki/Akaikeu信息准则>
[2]原始实验室。比较两个拟合函数。<https://www.originlab.com/doc/Origin-Help/PostFit-CompareFitFunc>
实例
此示例基于Astropy建模网页,复合模型部分。
>>> import numpy as np >>> from astropy.modeling import models, fitting >>> from astropy.stats.info_theory import akaike_info_criterion_lsq >>> np.random.seed(42) >>> # Generate fake data >>> g1 = models.Gaussian1D(.1, 0, 0.2) # changed this to noise level >>> g2 = models.Gaussian1D(.1, 0.3, 0.2) # and added another Gaussian >>> g3 = models.Gaussian1D(2.5, 0.5, 0.1) >>> x = np.linspace(-1, 1, 200) >>> y = g1(x) + g2(x) + g3(x) + np.random.normal(0., 0.2, x.shape) >>> # Fit with three Gaussians >>> g3_init = (models.Gaussian1D(.1, 0, 0.1) ... + models.Gaussian1D(.1, 0.2, 0.15) ... + models.Gaussian1D(2.4, .4, 0.1)) >>> fitter = fitting.LevMarLSQFitter() >>> g3_fit = fitter(g3_init, x, y) >>> # Fit with two Gaussians >>> g2_init = (models.Gaussian1D(.1, 0, 0.1) + ... models.Gaussian1D(2, 0.5, 0.1)) >>> g2_fit = fitter(g2_init, x, y) >>> # Fit with only one Gaussian >>> g1_init = models.Gaussian1D(amplitude=2., mean=0.3, stddev=.5) >>> g1_fit = fitter(g1_init, x, y) >>> # Compute the mean squared errors >>> ssr_g3 = np.sum((g3_fit(x) - y)**2.0) >>> ssr_g2 = np.sum((g2_fit(x) - y)**2.0) >>> ssr_g1 = np.sum((g1_fit(x) - y)**2.0) >>> akaike_info_criterion_lsq(ssr_g3, 9, x.shape[0]) -634.5257517810961 >>> akaike_info_criterion_lsq(ssr_g2, 6, x.shape[0]) -662.83834510232043 >>> akaike_info_criterion_lsq(ssr_g1, 3, x.shape[0]) -647.47312032659499
因此,从AIC值来看,我们更倾向于选择g2型拟合。然而,由于AIC的差异约为2.4,因此我们可以相当大程度地支持模型g3_拟合。我们应该拒绝g1型的。