代码在列的规范上引发错误

当我运行模型时,我不断收到以下值错误:


ValueError: Specifying the columns using strings is only supported for pandas DataFrames


这是错误的完整版本:


Traceback (most recent call last):


  File "/usr/lib/python3.8/site-packages/sklearn/utils/__init__.py", line 425, in _get_column_indices

    all_columns = X.columns


AttributeError: 'numpy.ndarray' object has no attribute 'columns'



During handling of the above exception, another exception occurred:


Traceback (most recent call last):


  File "/home/user/Python Practice/Working/Playstore/untitled0.py", line 48, in <module>

    run.fit(x,y)


  File "/usr/lib/python3.8/site-packages/sklearn/pipeline.py", line 330, in fit

    Xt = self._fit(X, y, **fit_params_steps)


  File "/usr/lib/python3.8/site-packages/sklearn/pipeline.py", line 292, in _fit

    X, fitted_transformer = fit_transform_one_cached(


  File "/usr/lib/python3.8/site-packages/joblib/memory.py", line 352, in __call__

    return self.func(*args, **kwargs)


  File "/usr/lib/python3.8/site-packages/sklearn/pipeline.py", line 740, in _fit_transform_one

    res = transformer.fit_transform(X, y, **fit_params)


  File "/usr/lib/python3.8/site-packages/sklearn/compose/_column_transformer.py", line 529, in fit_transform

    self._validate_remainder(X)


  File "/usr/lib/python3.8/site-packages/sklearn/compose/_column_transformer.py", line 327, in _validate_remainder

    cols.extend(_get_column_indices(X, columns))


  File "/usr/lib/python3.8/site-packages/sklearn/utils/__init__.py", line 427, in _get_column_indices

    raise ValueError("Specifying the columns using strings is only "


ValueError: Specifying the columns using strings is only supported for pandas DataFrames


关于如何修复它有什么想法吗?如果您需要的话,可以在这里找到所使用的数据。最初,我尝试在单个变压器变量下一次性执行所有列转换,但这不起作用,建议我在再次运行之前将它们分开。我这样做了,但结果如你所见。我需要一些帮助。谢谢你!


翻过高山走不出你
浏览 162回答 1
1回答

Helenr

我不会像这样分离柱变压器。这样,在您的run管道中,第一个ColumnTransformer col将 pandas 数据帧的输入转换为 numpy 数组。但是,列名称无法被挑选出来cb_(更糟糕的是,列顺序已更改,因此您不能依赖原始数据中的列索引)。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python