使用fit_transform進行資料轉換出現錯誤
2019/09/27 07:55 上午
機器學習共學討論版
herohsu
觀看數:10
回答數:2
收藏數:0
day23
我進行minMaxScalar(1,10), 將資料值限制在1~10, 但在輸入boxcox前不確定哪裡出錯了
會一直出現底下錯誤,請問是哪裡有問題?
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
# 將 Fare 取 boxcox 後, 看散佈圖, 並計算分數 (執行會有 error, 請試圖修正)
from scipy import stats
df_fixed = copy.deepcopy(df)
"""
Your Code Here, fix the error
"""
from sklearn.preprocessing import MinMaxScaler
scalar = MinMaxScaler( feature_range=(1, 10))
scalar.fit(df_fixed)
df_fixed = scalar.fit_transform(df_fixed)
df_fixed['Fare'] = stats.boxcox(df_fixed['Fare'])[0]
output=====
ndexError Traceback (most recent call last)
<ipython-input-47-da10ee54c24a> in <module>
10 df_fixed = scalar.fit_transform(df_fixed)
11
---> 12 df_fixed['Fare'] = stats.boxcox(df_fixed['Fare'])[0]
13 sns.distplot(df_fixed['Fare'][:train_num])
14 plt.show()
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices