【问题标题】:Tpot isnan errorTpot isnan 错误
【发布时间】:2020-04-05 12:30:51
【问题描述】:

我之前发布过类似的问题 (Categorical Data with tpot)。感谢 Randy,我能够让代码运行,但现在我在几个小时后停止了它,我收到了类似的错误:

  File "XXXXXXXX", line 832, in score
    if np.any(np.isnan(testing_features)):

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''

我不确定我是否错误地停止了它(我只是在 spyder 中按了 ctrl+c)还是有其他问题。我确保数据都是数字的,包括特征标题。知道可能是什么问题吗?

这是我正在运行的代码:

train_x, test_x, train_y, test_y=train_test_split(x,y)
train_x=pd.get_dummies(train_x).values
from tpot import TPOTRegressor

regressor=TPOTRegressor()
regressor.fit(train_x,train_y)
print(regressor.score(test_x,test_y))

我不知道如何显示训练和测试数组的内容。 train_x 是一个大小为 (2400,62) 的 float64,而 train_y 是一个 (2400,) 大小的系列。

【问题讨论】:

  • testing_features 的类型是什么?
  • 如何找到变量的类型?它在 tpot 代码中。对不起,我是 python 新手。
  • 那么,你能展示一下你用来调用导致错误的函数的代码吗?
  • 是的,很抱歉。我完全忘记了那部分。我将编辑上面的帖子以包含我的代码。
  • 哪一行导致错误? (编辑:我刚刚看到这是得分电话)。试试print(type(test_x), type(test_y))

标签: python tpot


【解决方案1】:

使用第一个解决方案给了我以下错误,

x_train = x_train.astype(np.float64)
x_test = x_test.astype(np.float64)
ValueError: setting an array element with a sequence.

将特征转换为 numpy 数组对我有用。即使它们最初是 numpy 数组

x_train = np.array(list(x_train), dtype=np.float)
x_test = np.array(list(x_test), dtype=np.float)

【讨论】:

    【解决方案2】:

    由于某种原因,当错误是类型时,TPOT 返回与isnan 相关的错误。确保您的特征转换为浮点数:

    X = X.astype(np.float64)
    

    【讨论】:

      猜你喜欢
      • 2021-03-10
      • 2017-12-02
      • 2020-05-08
      • 2016-06-23
      • 1970-01-01
      • 1970-01-01
      • 2019-10-05
      • 2021-10-21
      • 2020-12-27
      相关资源
      最近更新 更多