简体   繁体   English

输入包含对于 dtype“float64”来说太大的无穷大值

[英]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).所有数据类型都是float64int64 (虽然不在此列中)。 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.

相关问题 当我缩放数据时,输入包含 NaN、无穷大或对于 dtype('float64') 来说太大的值 - Input contains NaN, infinity or a value too large for dtype('float64') when I scale my data Scikit-learn:输入包含 NaN、无穷大或对于 dtype ('float64') 来说太大的值 - Scikit-learn : Input contains NaN, infinity or a value too large for dtype ('float64') ValueError:在预处理数据时,输入包含NaN,无穷大或对于dtype('float64')而言太大的值 - ValueError: Input contains NaN, infinity or a value too large for dtype('float64') while preprocessing Data fit_transform中的错误:输入包含NaN,无穷大或对于dtype('float64')而言太大的值 - Error in fit_transform: Input contains NaN, infinity or a value too large for dtype('float64') ValueError: 输入包含 NaN、无穷大或对于 dtype('float64') 来说太大的值。 对于我的 knn 模型 - ValueError: Input contains NaN, infinity or a value too large for dtype('float64'). for my knn model Python输入包含无穷大或值对于dtype('float64') - Python Input contains infinity or a value too large for dtype('float64') StandardScaler -ValueError:输入包含NaN,无穷大或对于dtype('float64')而言太大的值 - StandardScaler -ValueError: Input contains NaN, infinity or a value too large for dtype('float64') ValueError:输入包含 NaN、无穷大或对于 scikit-learn 的 dtype('float64') 来说太大的值 - ValueError: Input contains NaN, infinity or a value too large for dtype('float64') with scikit-learn ValueError:输入包含 NaN、无穷大或对于 dtype('float64') 来说太大的值。 在安装时 model - ValueError: Input contains NaN, infinity or a value too large for dtype('float64'). While fitting in model 输入包含无穷大或对于 dtype('float64') 错误来说太大的值 - Input contains infinity or a value too large for dtype('float64') error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM