ECDF 出現AttributeError: 'ECDF' object has no attribute 'max'錯誤
cdf = sm.distributions.ECDF(app_train['AMT_INCOME_TOTAL']) print cdf.max() plt.plot(list(cdf.index), cdf/cdf.max()) plt.xlabel('Value') plt.ylabel('ECDF') plt.xlim([cdf.index.min(), cdf.index.max() * 1.05]) # 限制顯示圖片的範圍
plt.ylim([-0.05,1.05]) # 限制顯示圖片的範圍 plt.show()
出現以錯誤
AttributeError Traceback (most recent call last)
<ipython-input-30-65d25d38b39a> in <module>()
6 cdf = sm.distributions.ECDF(app_train['AMT_INCOME_TOTAL'])
7
----> 8 print cdf.max()
9 plt.plot(list(cdf.index), cdf/cdf.max())
10 plt.xlabel('Value')
AttributeError: 'ECDF' object has no attribute 'max'
請問是需要轉data type嗎
回答列表
-
2019/05/02 上午 10:17張維元 (WeiYuan)贊同數:1不贊同數:0留言數:0
這邊提供一個使用參考套件實作的範例:
```
import statsmodels.api as sm
cdf = sm.distributions.ECDF(app_train['AMT_INCOME_TOTAL'])
plt.plot(cdf.x, cdf.y)
plt.xlabel('Value')
plt.ylabel('ECDF')
plt.xlim([cdf.x[1], cdf.x[-1] * 1.05]) # 限制顯示圖片的範圍
plt.ylim([-0.05,1.05]) # 限制顯示圖片的範圍
plt.show() ```
```
畫出來的圖會長這樣:
-
2019/05/02 下午 11:14許丕敏贊同數:0不贊同數:0留言數:0
cdf = sm.distributions.ECDF(app_train['AMT_INCOME_TOTAL'])
cdf= pd.Series(cdf.y, index=cdf.x)
print cdf
plt.plot(list(cdf.index), cdf/cdf.max())
plt.xlabel('Value')
plt.ylabel('ECDF')
plt.xlim([cdf.index.min(), cdf.index.max() * 1.05]) # 限制顯示圖片的範圍
plt.ylim([-0.05,1.05]) # 限制顯示圖片的範圍
可畫出圖形但是出現錯誤如下
ValueError: Axis limits cannot be NaN or Inf
請問這是什麼錯誤?謝謝
-
2019/05/03 上午 10:27張維元 (WeiYuan)贊同數:2不贊同數:0留言數:1
可畫出圖形但是出現錯誤如下ValueError: Axis limits cannot be NaN or Inf請問這是什麼錯誤?謝謝
=> 嗨,你可以試一下把 cdf.x,cdf.y 印出來,使用套件的產生的 cdf 的值會包含負無限的樣子。因此在
```
plt.xlim([cdf.index.min(), cdf.index.max() * 1.05])
```
這一行的地方會出錯,可以看看我上面的例子怎麼處理的:)