[英]Input contains infinity of value too large for dtype “float64”
So I am pretty new to python in general and I am trying to follow a tutorial to normalize and scale all of my data;所以我对 python 很陌生,我正在尝试按照教程来规范化和缩放我的所有数据; however, I keep getting an error.
但是,我不断收到错误消息。 I am using Scikit-learn with pandas.
我正在使用 Scikit-learn 和 pandas。 I've searched around and have tried just about everything I can think of, but I am still getting this error.
我已经四处搜索并尝试了几乎所有我能想到的,但我仍然收到这个错误。
I keep receiving this error, which traces back to preprocessing.scale:我不断收到这个错误,它可以追溯到 preprocessing.scale:
ValueError: Input contains infinity or a value too large for dtype('float64').
The column that's kicking back the error has a min of -10.3800048828125
and a max of 10.209991455078123
.消除错误的列的最小值为
-10.3800048828125
,最大值为10.209991455078123
。 All data types are float64
or int64
(not in this column though).所有数据类型都是
float64
或int64
(虽然不在此列中)。 I've tried multiple methods of getting rid of the infinities and NaNs but none of them seem to be working.我尝试了多种方法来摆脱无穷大和 NaN,但它们似乎都没有奏效。 If anyone has any advice it would be greatly appreciated!
如果有人有任何建议,将不胜感激!
The code that is getting the issue is here:出现问题的代码在这里:
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)
Here your problem: df.replace([np.inf, -np.inf], np.nan)
.这是您的问题:
df.replace([np.inf, -np.inf], np.nan)
。
Change the code as df = 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.