Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Output column names
#1
Hi Everyone,

I am running a model and then I output the most import features with this code.

feature_importances = grid_search.best_estimator_.feature_importances_
feature_importances
It gives me an array like this:
array([0.05771354, 0.05546155, 0.00769528, 0.03085979, 0.01987578,
0.05596404, 0.08724213, 0.04514583, 0.03068226, 0.03416644,
0.033704 , 0.03123091, 0.04680151, 0.04481024, 0.04322517,
0.04328215, 0.04302698, 0.04359057, 0.04307562, 0.04042718,
0.03971901, 0.03909929, 0.04083307, 0.04236768])

Is there anyway I can get python to print the column names as well so i know what variable has what weighting?

Thanks
Scott
Reply
#2
Where did this array come from?
The columns are the params (dictionary's keys) of the dataframe.
Reply
#3
(Jun-25-2018, 09:06 AM)Scott Wrote: Is there anyway I can get python to print the column names as well so i know what variable has what weighting?
The API returned you a numpy.array - numpy does not have a notion of a named column. Columns are properties of pandas.DataFrame - which is a wrapper over numpy arrays.

Whether your API returns values per columns or per rows, you have to combine your data accordingly
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Change column names from a file Nidhesh 2 2,968 Jul-08-2019, 06:00 AM
Last Post: Nidhesh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020