[英]ValueError: Input contains NaN, infinity or a value too large for dtype('float32') even though there is none that is like it
I was trying to fit my dataset into the CART model, but I keep on getting ValueError: Input contains NaN, infinity or a value too large for dtype('float32').我试图将我的数据集放入 CART model,但我一直收到 ValueError:输入包含 NaN、无穷大或对于 dtype('float32') 来说太大的值。 as an error.作为一个错误。 error problem错误问题
I had already double, even triple checked the dataset and I have seen that it does not contain any NaN, infinity, or anything that counts as that.我已经对数据集进行了两次甚至三次检查,发现它不包含任何 NaN、无穷大或任何可以算作 NaN 的东西。 I have also double checked if there were any blanks, and there weren't.我还仔细检查了是否有任何空白,但没有。 I tried everything including the most famous thread here, but to no avail.我尝试了一切,包括这里最著名的线程,但无济于事。 What could I be doing wrong?我做错了什么?
Edit:编辑:
flood_tr=df.sample(frac=0.75,random_state=42)
flood_test=df.drop(flood_tr.index)
y = flood_tr['flood_height']
mar_np = np.array(flood_tr['precipitation']) (mar_cat, mar_cat_dict) = stattools.categorical(mar_np, drop=True, dictnames=True)
mar_cat_pd = pd.DataFrame(mar_cat)
X = pd.concat((flood_tr[['elev']], mar_cat_pd), axis = 1)
rfy = np.ravel(y)
rf01 = RandomForestClassifier(n_estimators = 100,
criterion="gini").fit(X,rfy) #<--- this is where i got the error
here is the data set I used https://www.kaggle.com/datasets/giologicx/aegisdataset这是我使用的数据集https://www.kaggle.com/datasets/giologicx/aegisdataset
Your dataset has values larger than float32 (single-precision).您的数据集的值大于 float32(单精度)。 I would recommend doing the following.我建议执行以下操作。
X.round(dec) X.round(dec)
where dec == decimal precision in between something like (2~5)其中 dec == 小数精度介于 (2~5) 之间
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.