Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display/view `sklearn.utils.Bunch` data set?

I am going through a tutorial that uses sklearn.utils.Bunch as a data set:

cal_housing = fetch_california_housing()

I'm running this on a Databricks notebook.

I've read through the documentation that I can find like https://scikit-learn.org/stable/modules/generated/sklearn.utils.Bunch.html and search engines aren't yielding anything useful.

but how can I see/view what's in this data set?

like image 758
con Avatar asked Mar 24 '26 21:03

con


2 Answers

If I understood correctly, you can convert it to pandas dataframe:

df = california_housing.fetch_california_housing()
calf_hous_df = pd.DataFrame(data= df.data, columns=df.feature_names)    
calf_hous_df.sample(4)

enter image description here

Moreover, you can see attributes:

df.keys()
dict_keys(['data', 'target', 'feature_names', 'DESCR'])
like image 152
Frightera Avatar answered Mar 27 '26 09:03

Frightera


You could read the data using method items() and keys() as referencing in sklearn.utils.Bunch. But there is no method similar to head() in Pandas Dataframe. dataset.items() will show all data.

I've tried using iris dataset as follows.

    import sklearn
    from sklearn import datasets
    
    # load iris dataset
    iris = datasets.load_iris()
    print('Data type:', type(iris))
    iris.items()
    print('Keys: ', iris.keys()) #show all the keys
    iris.get('feature_names')
like image 22
Yugo Gautomo Avatar answered Mar 27 '26 09:03

Yugo Gautomo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!