where does feature_names is Scikit-learn come from?

Viewed 583

I am learning scikit-learn and I ran this code, which imports the breast cancer csv

from sklearn.datasets import load_breast_cancer
cancer_data = load_breast_cancer()
#print(cancer_data.DESCR)

When I run cancer_data.keys(), it brings back the following:

dict_keys(['data', 'target', 'frame', 'target_names', 'DESCR', 'feature_names', 'filename'])

There are no column headers in this csv, yet running cancer_data.feature_names gives me a list of column names. Where is this information coming from?

thanks

2 Answers

These names are define in the load_breast_cancer() function. See source code for details.

In original source data file doesn't have columns names, there is separate file with description of the data.

If you run type(cancer_data) to check what is the type of your data you will get something like this sklearn.utils.Bunch and according to the official documentation Bunch objects are sometimes used as an output for functions and methods. They extend dictionaries by enabling values to be accessed by key, bunch["value_key"], or by an attribute, bunch.value_key.

Since they extend dictionaries you can use cancer_data.keys() to get the keys which is what you are getting as an output.

Follow the links to know more

Related