首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Scipy.stats t矩提取问题

Scipy.stats t矩提取问题
EN

Stack Overflow用户
提问于 2019-08-04 14:38:57
回答 1查看 94关注 0票数 0

我正在尝试从一个学生中提取斜度和峰度,这是我对一些非正常数据的拟合。

提取平均值和stdev没有问题,但不知道提取和打印学生t斜和峰度所需的代码。

代码语言:javascript
复制
mu_norm, sig_norm = norm.fit(returns) # extract the mean and stdev of the closest normal distribution fit
print("Normal mean is {0:.8f}, stdev is {1:.8f}".format(mu_norm, sig_norm))
dx = 0.0001 # resolution of the distribution
x = np.arange(-1, 1, dx)
pdf_n = norm.pdf(x, mu_norm, sig_norm)

nu, mu_t, sig_t = t.fit(returns) # extract the mean and stdev of the closest Student-t distribution fit
nu = np.round(nu)
print("Student-t mean is {0:.8f}, stdev is {1:.8f}, dof is {2}".format(mu_t, sig_t, nu))
pdf_t = t.pdf(x, nu, mu_t, sig_t)

print('Maximum: ', returns.max())
print('Minimum: ', returns.min())
print('Norm_Skew', returns.skew())
print('Norm_Kurtosis', returns.kurtosis())

我想添加以下输出:

代码语言:javascript
复制
print('t_Skew', returns.tskew())
print('t_Kurtosis', returns.tkurtosis())
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-19 01:40:06

这是我想出来的,

代码语言:javascript
复制
import numpy as np
from scipy.stats import norm, t
import matplotlib.pyplot as plt

np.random.seed(42)
X=np.random.randn(100)
mu_n, sig_n = norm.fit(X)
# to get skew and curtosis of normal distribution
print('normal distribution, mean, variance, skew, kurtosis', norm.stats(mu_n, sig_n, moments='mvsk'))
nu, mu_t, sig_t = t.fit(X)
nu = round(nu)
# to get skew and curtosis of t distribution
print('t distribution, mean, variance, skew, kurtosis', t.stats(nu, mu_t, sig_t, moments='mvsk'))

给我

代码语言:javascript
复制
normal distribution, mean, variance, skew, kurtosis (array(-0.10384652), array(0.81652219), array(0.), array(0.))
t distribution, mean, variance, skew, kurtosis (array(-0.10382961), array(0.81653396), array(0.), array(1.46540974e-06))

密谋,

代码语言:javascript
复制
x_plot = np.linspace(-2, 2, 100)
y_plot_n = norm.pdf(x_plot, mu_n, sig_n)
y_plot_t = t.pdf(x_plot, nu, mu_t, sig_t)
f, (n_plot, t_plot) = plt.subplots(1, 2)
n_plot.set_title('normal dist')
n_plot.plot(x_plot, y_plot_n)
t_plot.plot(x_plot, y_plot_t)
t_plot.set_title('t dist')
plt.show()

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57347475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档