【问题标题】:Error in importing export_text from sklearn.tree.export从 sklearn.tree.export 导入 export_text 时出错
【发布时间】: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


    【解决方案1】:

    问题在于 sklearn 版本。

    更新的 sklearn 可以解决这个问题。

    sklearn.版本 0.21.3 将解决此问题。

    除使用 sklearn 外,可按要求打印的任何其他方法/代码。

    【讨论】:

      【解决方案2】:

      我认为这只是

      from scikit.tree import export_text
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-05
        • 2020-06-07
        • 2021-11-03
        • 2010-10-12
        • 2017-07-22
        • 2015-09-20
        相关资源
        最近更新 更多