Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

one hot encoding

from sklearn.preprocessing import OneHotEncoder
encoder = preprocessing.OneHotEncoder(handle_unknown='ignore')
y = np.array([1, 2, 1, 3])
y = y.reshape(-1,1)
encoder.fit(y)
y_oh = encoder.transform(y).toarray()
print(y_oh)
>>[[1. 0. 0.]
 [0. 1. 0.]
 [1. 0. 0.]
 [0. 0. 1.]]
Comment

PREVIOUS NEXT
Code Example
Python :: how to execute a python file from another python file 
Python :: creating empty set and append python 
Python :: pyqt5 image center 
Python :: Python Roman to Integer method 2 
Python :: download from colab to local drive 
Python :: pandas dataframe compare two dataframes and extract difference 
Python :: replace nan with 0 pandas 
Python :: import python script from another directory 
Python :: python check if there is internet connection 
Python :: django q objects 
Python :: python is inf 
Python :: custom position for axis matplotlib 
Python :: convert csv file into python list 
Python :: asyncio run 
Python :: how to take input for list in one line in python 
Python :: numpy moving average 
Python :: tensorflow matrix multiplication 
Python :: Python NumPy broadcast_to() Function Example 
Python :: change dataframe to list 
Python :: joins in pandas 
Python :: pip install django celery results 
Python :: how to take date as input in python 
Python :: pandas reset index 
Python :: python Modulo 10^9+7 (1000000007) 
Python :: Python string to var 
Python :: python compare floats 
Python :: python alphabetical order 
Python :: django reverse function 
Python :: How to develop a UDP echo server in python? 
Python :: django admin 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =