Traceback (most recent call last): File "C:\Users\木南\PycharmProjects\pythonProject1\venv\test.py", line 27, in <module> clf.fit(X_train, y_train) File "C:\Users\木南\PycharmProjects\pythonProject1\venv\lib\site-packages\sklearn\tree\_classes.py", line 889, in fit super().fit( File "C:\Users\木南\PycharmProjects\pythonProject1\venv\lib\site-packages\sklearn\tree\_classes.py", line 186, in fit X, y = self._validate_data( File "C:\Users\木南\PycharmProjects\pythonProject1\venv\lib\site-packages\sklearn\base.py", line 548, in _validate_data self._check_feature_names(X, reset=reset) File "C:\Users\木南\PycharmProjects\pythonProject1\venv\lib\site-packages\sklearn\base.py", line 415, in _check_feature_names feature_names_in = _get_feature_names(X) File "C:\Users\木南\PycharmProjects\pythonProject1\venv\lib\site-packages\sklearn\utils\validation.py", line 1903, in _get_feature_names raise TypeError( TypeError: Feature names are only supported if all input features have string names, but your input has ['int', 'str'] as feature name / column name types. If you want feature names to be stored and validated, you must convert them all to strings, by using X.columns = X.columns.astype(str) for example. Otherwise you can remove feature / column names from your input data, or convert them all to a non-string data type.
时间: 2023-07-06 21:28:24 浏览: 227
Mac下anaconda中Spyder打开报错Traceback(most recent call last)…问题
5星 · 资源好评率100%
这是一个错误信息,看起来是在使用 scikit-learn 中的决策树模型时出现的。错误信息提示说输入的特征名只支持字符串类型,但是输入中出现了 int 和 str 类型的特征名。解决这个问题有两种方法,一种是将所有的特征名都转换成字符串类型,例如可以使用 X.columns = X.columns.astype(str) 来实现;另一种方法是从输入数据中删除特征名,或者将所有的特征名都转换成非字符串类型。
阅读全文