View catagorical values mapping

,

Screen Link: https://app.dataquest.io/m/89/introduction-to-decision-trees/3/converting-categorical-variables

In the above screen, we converted categorical values to numerical values.

My question is how can I view this mapping using the code?

There’s nothing complicated to the mapping.

If you print out the unique values of the race column you will get -

[’ White’ ’ Black’ ’ Asian-Pac-Islander’ ’ Amer-Indian-Eskimo’ ’ Other’]

That’s a total of 5 values.

So, the mapping is just assigning each value a number. The numbers are based on the length of the above, so that’s 5. So each value will be assigned a number from 0 to 4.

So, the result of the mapping might end up as -

Original Mapped
’ White’ 0
’ Black’ 1
’ Asian-Pac-Islander’ 2
’ Amer-Indian-Eskimo’ 3
’ Other’ 4

The strings were mapped from 0 to 4 (total of 5).

And that’s pretty much it.

You can print out the values before and after the mapping to check which ones mapped to which value. That should be fairly simple to do.

Thanks for the answer.

I was trying to print a dictionary containng the mapping as demonstrated here. So far It didn’t work. Is there any way to do this?

Also, can you please answer this question What is null correlation? of mine?