Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

OneHotEncoder sklearn python

from sklearn.preprocessing import OneHotEncoder
>>> enc = OneHotEncoder(handle_unknown='ignore')
>>> X = [['Male', 1], ['Female', 3], ['Female', 2]]
>>> enc.fit(X)
OneHotEncoder(handle_unknown='ignore')
>>> enc.categories_
[array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object)]
>>> enc.transform([['Female', 1], ['Male', 4]]).toarray()
array([[1., 0., 1., 0., 0.],
       [0., 1., 0., 0., 0.]])
>>> enc.inverse_transform([[0, 1, 1, 0, 0], [0, 0, 0, 1, 0]])
array([['Male', 1],
       [None, 2]], dtype=object)
>>> enc.get_feature_names_out(['gender', 'group'])
array(['gender_Female', 'gender_Male', 'group_1', 'group_2', 'group_3'], ...)
Comment

OneHotEncoder()

enc = OneHotEncoder()
enc.fit(df[["Temperature"]])
onehotlabels = enc.transform(df[["Temperature"]]).toarray()
Comment

PREVIOUS NEXT
Code Example
Python :: python to c# 
Python :: Python program to print all odd numbers in a range 
Python :: python series to list of string 
Python :: date-fns difference in days 
Python :: how to split a string by character in python 
Python :: python file open try except error 
Python :: how to check the size of a file in python 
Python :: change dictionary value python 
Python :: ros python service server 
Python :: how to calculate z score in python 
Python :: take screenshot of video python 
Python :: basic games to code in python 
Python :: pdf to csv 
Python :: python program to add two numbers using function 
Python :: chatbot python 
Python :: return max value in groupby pyspark 
Python :: print( n ) in python 
Python :: generate binay image python 
Python :: how to get the duration of audio python 
Python :: python change character in string 
Python :: merge dataframe pandas 
Python :: dictionary indexing python 
Python :: how to run pyttsx3 in a loop 
Python :: how to iterate through a list in python 
Python :: python spammer 
Python :: args kwargs python 
Python :: python list fill nan 
Python :: flask debugtoolbar 
Python :: access first element of dictionary python 
Python :: suppress python vs try/except pass 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =