[HW6] 繪製ecdf
2019/05/03 上午 07:10
機器學習共學討論版
吳孟和
觀看數:18
回答數:1
收藏數:0
ml100-2
ecdf
ml100-2-d06
# 繪製 Empirical Cumulative Density Plot (ECDF) """ YOUR CODE HERE """ data = app_train['AMT_INCOME_TOTAL'] num_bins = 50 # Use the histogram function to bin the data counts, bin_edges = np.histogram(data, bins=num_bins, normed=True) # Now find the cdf cdf = np.cumsum(counts) #plot plt.plot(list(cdf.index), cdf/cdf.max())
如上之取得cdf的方式是否有誤,因在要畫圖時,顯示"'numpy.ndarray' object has no attribute 'index'",應該是變數格式有錯誤?再麻煩解答,感恩!
回答列表
-
2019/05/03 上午 09:55張維元 (WeiYuan)贊同數:0不贊同數:0留言數:2
嗨,你的排版可以調整一下嗎?這樣很難閱讀 QQ 看起來是 cdf 定義好,可能要看你怎麼定義的才會知道錯誤在哪?
這邊提供一個使用參考套件實作的範例:
```
import statsmodels.api as sm
cdf = sm.distributions.ECDF(app_train['AMT_INCOME_TOTAL'])
plt.plot(cdf.x, cdf.y)
....
```
畫出來的圖會長這樣: