質問

I am loading the built-in boston data set in scikit library as:

from sklearn.datasets import load_boston bdata = load_boston()

I want to extract all the values in the first column, which is called as CRIM. I Have written a line like: plt.scatter(bdata.CRIM,bdata.target,color='blue')

But I am getting an error as "AttributeError: 'Bunch' object has no attribute 'CRIM'"

How do I access the elements of the column titled 'CRIM' ?

役に立ちましたか?

解決

The data values are stored in the data attribute, to access all the values of the first column, you use numpy's slice syntax. In this case you want:

plt.scatter(bdata.data[:,0],bdata.target,color='blue')

The colon indicates you're selecting "all" for the specific axis (which is the first axis, the "rows" in this case) and the 0 indicates you want the first element for all the rows - that is the first column.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top