我正在使用Python(Richart,Pedro Coelho)書中的Building Machine Learning Systems的逐行示例。NameError:未定義名稱'labels'
進口虹膜數據集後,我們希望與Setosa
data = load_iris()
features = data['data']
plength = features[:, 2]
# use numpy operations to get setosa features
is_setosa = (labels == 'setosa')
提取那些我得到這個
>>> is_setosa = (labels == 'setosa')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'labels' is not defined
我想這是錯字,所以我嘗試
>>> is_setosa = plenght(labels == 'setosa')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'plenght' is not defined
>>> is_setosa = plength(labels == 'setosa')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'labels' is not defined
>>> is_setosa = data(labels == 'setosa')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'labels' is not defined
什麼我現在應該做什麼? 如何檢查數據對象?
>>> data.labels
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/milenko/miniconda2/lib/python2.7/site-packages/sklearn/datasets/base.py", line 58, in __getattr__
raise AttributeError(key)
AttributeError: labels
>>> data.dtypes
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/milenko/miniconda2/lib/python2.7/site-packages/sklearn/datasets/base.py", line 58, in __getattr__
raise AttributeError(key)
AttributeError: dtypes
這是描述
- class:\n - Iris-Setosa\n - Iris-Versicolour\n - Iris-Virginica\n :
很明顯,變量'labels'沒有被定義! – luoluo
你可以做一些類似data ['labels']或data.labels的東西......檢查數據對象 – FLab
你不想在你的'is_setosa'變量中設置一個布爾值。爲此,你正在比較'labels =='setosa''。現在'標籤'沒有定義過。介意寫上面的聲明像'labels =「」'? – ishaan