当我运行模型时,我不断收到以下值错误: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.columnsAttributeError: '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关于如何修复它有什么想法吗?如果您需要的话,可以在这里找到所使用的数据。最初,我尝试在单个变压器变量下一次性执行所有列转换,但这不起作用,建议我在再次运行之前将它们分开。我这样做了,但结果如你所见。我需要一些帮助。谢谢你!
1 回答
Helenr
TA贡献1780条经验 获得超3个赞
我不会像这样分离柱变压器。这样,在您的run
管道中,第一个ColumnTransformer
col
将 pandas 数据帧的输入转换为 numpy 数组。但是,列名称无法被挑选出来cb_
(更糟糕的是,列顺序已更改,因此您不能依赖原始数据中的列索引)。
添加回答
举报
0/150
提交
取消