'function'对象没有属性'data'

时间:2017-07-28 01:07:45

标签: python scikit-learn

from sklearn import datasets 
iris=datasets.load_iris
X = iris.data
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-15-12a2d725131f> in <module>()
----> 1 X = iris.data

AttributeError: 'function' object has no attribute 'data

I load iris dataset from sklearn ,but when i write "X = iris.data",an error occur as "AttributeError: 'function' object has no attribute 'data'"

2 个答案:

答案 0 :(得分:6)

load_iris是一个函数,需要这样调用:

from sklearn import datasets 
iris=datasets.load_iris()
X = iris.data

答案 1 :(得分:0)

使用load_iris()代替load_iris,像这样,

iris = datasets.load_iris()