データプロットの練習でpythonライブラリのseabornでカーネル密度推定をしようとするとエラーが返ってきます。
他のグラフは普通に表示できるんですがkdeplotだけはうまくいきません。同じような現象にあったり解決法を知っている方教えていただけると嬉しいです。
(python3.5.2)
コード(作業環境:jupyter notebook)
python
1import pandas as pd 2import numpy as np 3import matplotlib.pyplot as plt 4import seaborn as sns 5%matplotlib inline 6 7dataset = np.random.randn(100) 8sns.set() 9sns.kdeplot(dataset)
エラーメッセージ
TypeError Traceback (most recent call last)
<ipython-input-5-067dcccd3fa1> in <module>()
1 dataset = np.random.randn(100)
2 sns.set()
----> 3 sns.kdeplot(dataset)
~/anaconda/lib/python3.5/site-packages/seaborn/distributions.py in kdeplot(data, data2, shade, vertical, kernel, bw, gridsize, cut, clip, legend, cumulative, shade_lowest, cbar, cbar_ax, cbar_kws, ax, **kwargs)
655 ax = _univariate_kdeplot(data, shade, vertical, kernel, bw,
656 gridsize, cut, clip, legend, ax,
--> 657 cumulative=cumulative, **kwargs)
658
659 return ax
~/anaconda/lib/python3.5/site-packages/seaborn/distributions.py in _univariate_kdeplot(data, shade, vertical, kernel, bw, gridsize, cut, clip, legend, ax, cumulative, **kwargs)
271 x, y = _statsmodels_univariate_kde(data, kernel, bw,
272 gridsize, cut, clip,
--> 273 cumulative=cumulative)
274 else:
275 # Fall back to scipy if missing statsmodels
~/anaconda/lib/python3.5/site-packages/seaborn/distributions.py in _statsmodels_univariate_kde(data, kernel, bw, gridsize, cut, clip, cumulative)
343 fft = kernel == "gau"
344 kde = smnp.KDEUnivariate(data)
--> 345 kde.fit(kernel, bw, fft, gridsize=gridsize, cut=cut, clip=clip)
346 if cumulative:
347 grid, y = kde.support, kde.cdf
~/anaconda/lib/python3.5/site-packages/statsmodels/nonparametric/kde.py in fit(self, kernel, bw, fft, weights, gridsize, adjust, cut, clip)
144 density, grid, bw = kdensityfft(endog, kernel=kernel, bw=bw,
145 adjust=adjust, weights=weights, gridsize=gridsize,
--> 146 clip=clip, cut=cut)
147 else:
148 density, grid, bw = kdensity(endog, kernel=kernel, bw=bw,
~/anaconda/lib/python3.5/site-packages/statsmodels/nonparametric/kde.py in kdensityfft(X, kernel, bw, weights, gridsize, adjust, clip, cut, retgrid)
504 zstar = silverman_transform(bw, gridsize, RANGE)*y # 3.49 in Silverman
505 # 3.50 w Gaussian kernel
--> 506 f = revrt(zstar)
507 if retgrid:
508 return f, grid, bw
~/anaconda/lib/python3.5/site-packages/statsmodels/nonparametric/kdetools.py in revrt(X, m)
18 if m is None:
19 m = len(X)
---> 20 y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j
21 return np.fft.irfft(y)*m
22
TypeError: slice indices must be integers or None or have an index method
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。