![](/img/trans.png)
[英]Input contains NaN, infinity or a value too large for dtype('float64') when I scale my data
[英]Input contains infinity of value too large for dtype “float64”
所以我對 python 很陌生,我正在嘗試按照教程來規范化和縮放我的所有數據; 但是,我不斷收到錯誤消息。 我正在使用 Scikit-learn 和 pandas。 我已經四處搜索並嘗試了幾乎所有我能想到的,但我仍然收到這個錯誤。
我不斷收到這個錯誤,它可以追溯到 preprocessing.scale:
ValueError: Input contains infinity or a value too large for dtype('float64').
消除錯誤的列的最小值為-10.3800048828125
,最大值為10.209991455078123
。 所有數據類型都是float64
或int64
(雖然不在此列中)。 我嘗試了多種方法來擺脫無窮大和 NaN,但它們似乎都沒有奏效。 如果有人有任何建議,將不勝感激!
出現問題的代碼在這里:
def preprocess_df(df):
df = df.drop('future', 1)
df.replace([np.inf, -np.inf], np.nan)
df.fillna(method='bfill', inplace=True)
df.dropna(inplace=True)
for col in df.columns:
print("Trying Column: " + col)
if col != "target":
df[col] = df[col].pct_change()
df.dropna(inplace=True)
df[col] = preprocessing.scale(df[col].values)
df.dropna(inplace=True)
sequential_data = []
prev_days = deque(maxlen=SEQ_LEN)
for i in df.values:
prev_days.append([n for n in i[:-1]]) #appends every column to the prev days list, except for target (we don't want that to be known)
if len(prev_days) == SEQ_LEN:
sequential_data.append([np.array(prev_days), i[:-1]])
random.shuffle(sequential_data)
這是您的問題: df.replace([np.inf, -np.inf], np.nan)
。
將代碼更改為df = df.replace([np.inf, -np.inf], np.nan)
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.