[英]Input contains NaN, infinity or a value too large for dtype('float32')
How do I fix this error message , "ValueError: Input contains NaN, infinity or a value too large for dtype('float32')"如何修复此错误消息,“ValueError: Input contains NaN, infinity or a value too large for dtype('float32')”
# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Loading the dataset
data = pd.read_csv(r'C:\Users\sam.jones\Desktop\Fixed Income project\Data Pull\Data\Fixed Income_Data dump_2018.csv',error_bad_lines=False,encoding = "ISO-8859-2")
X = np.array([data.iloc[:,158].values])
Y = data.iloc[:,92].values
#Fitting Random Forest Regression to the dataset
from sklearn.ensemble import RandomForestRegressor
regressor = RandomForestRegressor(n_estimators = 10, random_state = 0)
regressor.fit(X,Y)
Input might have Nan's.输入可能有南的。 So use np.nan_to_num(X)
to fill them with zeroes first.所以先使用np.nan_to_num(X)
用零填充它们。
尝试声明一个变量。
x = x.fillna(test.mean())
In my case that error was due to big numbers, in particular I found those with scientific notation, such as 3.63E+08, 1.25E+09... The solution is to replace those numbers with something smaller: you can either simply replace them with x / 1000 or, the best solution, use a function to scale or normalise the data.在我的情况下,错误是由于大数字造成的,特别是我发现那些带有科学记数法的数字,例如 3.63E+08、1.25E+09... 解决方案是用较小的数字替换这些数字:您可以简单地替换它们使用 x / 1000,或者最好的解决方案是使用函数来缩放或规范化数据。 After that, you can train your model之后,您可以训练您的模型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.