gpt4 book ai didi

python - 输入类型 Python Imputer 不支持 Isnan

转载 作者:行者123 更新时间:2023-12-01 01:59:39 25 4
gpt4 key购买 nike

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

#Import Data set

dataset= pd.read_csv('Data.csv')
X = dataset.iloc[:,:-1].values
Y = dataset.iloc[:,3].values

#Taking Care of The Missing Data
from sklearn.preprocessing import Imputer

imputer = Imputer(missing_values='nan',strategy='mean',axis=0)
imputer = imputer.fit(X[:,1:3])

X[:,1:3] = imputer.transform(X[:,1:3])

我正在遵循本教程系列,并且完全按照他的导师对我所做的那样,当然存在代码中提到的错误。一个潜在的解决方案当然会非常有帮助。提前致谢。

Error : if value_to_mask == "NaN" or np.isnan(value_to_mask):
TypeError: ufunc 'isnan' not supported for the input types, and the
inputs could not be safely coerced to any supported types according to
the casting rule ''safe''

最佳答案

尝试:

imputer = Imputer(missing_values=np.nan,strategy='mean',axis=0)

imputer = Imputer(missing_values='NaN',strategy="mean",axis=0)

documentation 中所述

关于python - 输入类型 Python Imputer 不支持 Isnan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49824027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com