• 카테고리

    질문 & 답변
  • 세부 분야

    딥러닝 · 머신러닝

  • 해결 여부

    해결됨

plot을 그릴때 데이터에 결측치가 있으면 그려지지 않는 컬럼이 있습니다.

20.09.16 10:55 작성 조회수 365

0

show_hist_by_target() 함수 호출 시 'ValueError: cannot convert float NaN to integer' 에러가 발생하는데요. 혹시 seaborn 라이브러리의 버전 문제나 먼저 결측치 제거 작업을 거쳐야 할까요?

답변 10

·

답변을 작성해보세요.

2

실습에 사용되는 버전은 scipy 버전은 1.5.0 입니다.  지금 seaborn에서 scipy의 statsmodel 을 이용해서 KDE를 그리는 작업을 하는데 여기서 오류가 나는것 같습니다.  버전 upgrade가 필요해 보입니다.

이렇게 기존에 구성된 개인 환경을 사용해서 개별 패키지를 각각 upgrade하여서 실습하시는 것 보다는 강의 동영상에 나와 있는데로 Anaconda를 download 받으시고, conda 기반으로 환경 셋업을 하시고 실습을 하시는게 어떨지요?

1

groov님의 프로필

groov

질문자

2020.09.16

네. 이미 개인적으로 환경이 구성되어 있어 초반 환경 설정 강의를 넘기고 진행해서 그런거 같습니다. 답변 주셔서 감사드립니다.

1

groov님의 프로필

groov

질문자

2020.09.16

네. 1.4.1 입니다.

1

scipy 버전이 안맞는것 같습니다. 버전을 알 수 있을까요?

1

groov님의 프로필

groov

질문자

2020.09.16

네. 다음과 같습니다.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/statsmodels/nonparametric/kde.py in kdensityfft(X, kernel, bw, weights, gridsize, adjust, clip, cut, retgrid)
    450     try:
--> 451         bw = float(bw)
    452     except:

ValueError: could not convert string to float: 'scott'

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
<ipython-input-8-9527850a704a> in <module>
      1 columns = ['AMT_REQ_CREDIT_BUREAU_HOUR']
----> 2 show_hist_by_target(app_train, columns)

<ipython-input-7-551ac81feeb7> in show_hist_by_target(df, columns)
      6         fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(12, 4), squeeze=False)
      7         sns.violinplot(x='TARGET', y=column, data=df, ax=axs[0][0] )
----> 8         sns.distplot(df[cond_0][column], ax=axs[0][1], label='0', color='blue')
      9         sns.distplot(df[cond_1][column], ax=axs[0][1], label='1', color='red')

/opt/conda/lib/python3.7/site-packages/seaborn/distributions.py in distplot(a, bins, hist, kde, rug, fit, hist_kws, kde_kws, rug_kws, fit_kws, color, vertical, norm_hist, axlabel, label, ax)
    231     if kde:
    232         kde_color = kde_kws.pop("color", color)
--> 233         kdeplot(a, vertical=vertical, ax=ax, color=kde_color, **kde_kws)
    234         if kde_color != color:
    235             kde_kws["color"] = kde_color

/opt/conda/lib/python3.7/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)
    703         ax = _univariate_kdeplot(data, shade, vertical, kernel, bw,
    704                                  gridsize, cut, clip, legend, ax,
--> 705                                  cumulative=cumulative, **kwargs)
    706 
    707     return ax

/opt/conda/lib/python3.7/site-packages/seaborn/distributions.py in _univariate_kdeplot(data, shade, vertical, kernel, bw, gridsize, cut, clip, legend, ax, cumulative, **kwargs)
    293         x, y = _statsmodels_univariate_kde(data, kernel, bw,
    294                                            gridsize, cut, clip,
--> 295                                            cumulative=cumulative)
    296     else:
    297         # Fall back to scipy if missing statsmodels

/opt/conda/lib/python3.7/site-packages/seaborn/distributions.py in _statsmodels_univariate_kde(data, kernel, bw, gridsize, cut, clip, cumulative)
    365     fft = kernel == "gau"
    366     kde = smnp.KDEUnivariate(data)
--> 367     kde.fit(kernel, bw, fft, gridsize=gridsize, cut=cut, clip=clip)
    368     if cumulative:
    369         grid, y = kde.support, kde.cdf

/opt/conda/lib/python3.7/site-packages/statsmodels/nonparametric/kde.py in fit(self, kernel, bw, fft, weights, gridsize, adjust, cut, clip)
    138             density, grid, bw = kdensityfft(endog, kernel=kernel, bw=bw,
    139                     adjust=adjust, weights=weights, gridsize=gridsize,
--> 140                     clip=clip, cut=cut)
    141         else:
    142             density, grid, bw = kdensity(endog, kernel=kernel, bw=bw,

/opt/conda/lib/python3.7/site-packages/statsmodels/nonparametric/kde.py in kdensityfft(X, kernel, bw, weights, gridsize, adjust, clip, cut, retgrid)
    451         bw = float(bw)
    452     except:
--> 453         bw = bandwidths.select_bandwidth(X, bw, kern) # will cross-val fit this pattern?
    454     bw *= adjust
    455 

/opt/conda/lib/python3.7/site-packages/statsmodels/nonparametric/bandwidths.py in select_bandwidth(x, bw, kernel)
    172         # eventually this can fall back on another selection criterion.
    173         err = "Selected KDE bandwidth is 0. Cannot estimate density."
--> 174         raise RuntimeError(err)
    175     else:
    176         return bandwidth

RuntimeError: Selected KDE bandwidth is 0. Cannot estimate density.

0

강의에 사용된 pandas 버전은 1.0.5 입니다만, KDE 변환 오류는 histogram시 나타날 수 있습니다. 먼저 오류 메시지를 이미지 캡처하지 마시고, 전체를 텍스트로 여기에 올려 주실수 있나요?

0

groov님의 프로필

groov

질문자

2020.09.16

답변 감사드립니다. seaborn 버전 업그레이드 이후 위에 오류는 해결되었습니다.

다시 실행 해보니 'AMT_REQ_CREDIT_BUREAU_HOUR' 컬럼에서 아래와 같은 에러가 발생하였습니다.

실습 코드는 그대로 사용하고 있고, pandas 버전은 1.1.2 입니다. 해당 library 버전 정보를 알려주시면 동일하게 맞춰서 다시 해보겠습니다. 감사합니다.

0

실습 코드를 그대로 사용하시는데, 에러가 난다면 일단 seaborn을 0.10 으로 upgrade 부탁드립니다.

혹시 그래도 오류가 계속 발생하신다면 이번엔 pandas 버전을 말씀해 주십시요.

0

groov님의 프로필

groov

질문자

2020.09.16

안녕하세요.  아래와 같이 AMT_ANNUITY 컬럼의 distplot을 그릴때 발생합니다.

seaborn library 버전은 0.9.0 입니다.

0

안녕하십니까,

어떤 테이블의 어떤 컬럼인지 알수 있을 까요?

그리고 아래와 같이 seaborn 버전도 부탁드립니다. 

import seaborn as sns

print(sns.__version__)

감사합니다.