【发布时间】:2020-01-07 23:16:57
【问题描述】:
我有一个决策树分类器,从 sklearn.tree.export 导入 export_text 时出现如下错误,
ImportError: cannot import name 'export_text' from 'sklearn.tree.export' (C:\ProgramData\Anaconda3\lib\site-packages\sklearn\tree\export.py)
有没有办法解决这个问题
我已经尝试过documentation中提到的代码,如下:
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree.export import export_text
iris = load_iris()
X = iris['data']
y = iris['target']
decision_tree = DecisionTreeClassifier(random_state=0, max_depth=2)
decision_tree = decision_tree.fit(X, y)
r = export_text(decision_tree, feature_names=iris['feature_names'])
print(r)
|--- petal width (cm) <= 0.80
| |--- class: 0
|--- petal width (cm) > 0.80
| |--- petal width (cm) <= 1.75
| | |--- class: 1
| |--- petal width (cm) > 1.75
| | |--- class: 2
我正在使用我的 python-3.7.3 和其他相关库版本作为
import sklearn
import numpy
import scipy
import joblib
print(sklearn.__version__) == > 0.20.3
print(numpy.__version__) === > 1.16.2
print(scipy.__version__) ==> 1.2.1
print(joblib.__version__) ==> 0.13.2
错误如下:
ImportError: cannot import name 'export_text' from 'sklearn.tree.export' (C:\ProgramData\Anaconda3\lib\site-packages\sklearn\tree\export.py)
【问题讨论】:
标签: python scikit-learn decision-tree