Quantcast
Channel: Data Science, Analytics and Big Data discussions - Latest topics
Viewing all articles
Browse latest Browse all 4448

OneHotEncoding in Python

$
0
0

@shan4224 wrote:

Hi..

I am new to Python. Is OneHotEncoding similar to creation of dummy variables ?
Tried the following codes in python OneHotEncoding:

from sklearn.preprocessing import OneHotEncoder
enc = OneHotEncoder()
enc.fit([[0, 0, 3], [1, 1, 0], [0, 2, 1], [1, 0, 2]])

enc.transform([[0, 1, 1]])

<1x9 sparse matrix of type '' with 3 stored elements in Compressed Sparse Row format>

enc.transform transform [[0, 1, 1]] using one-hot encoding.
How the following code result in output of the array ?

In [1] : enc.transform([[0, 1, 1]]).toarray()
Out[1] : array([[ 1., 0., 0., 1., 0., 0., 1., 0., 0.]])

An explanation with steps will be helpful.

Thanks

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4448

Trending Articles