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 :: sum all values of a dictionary python 
Python :: jupyter notebook check memory usage 
Python :: How to find majority element in a sequence of values using Boyer-Moore vote algorithm? 
Python :: polarean share price 
Python :: python selenium screenshot 
Python :: get every nth element in list python 
Python :: how to access all the elements of a matrix in python using for loop 
Python :: pygame event mouse right click 
Python :: coronavirus program in python 
Python :: static dir in django python 
Python :: wtform custom validator example 
Python :: create jwt token python 
Python :: tkinter button background color mac 
Python :: add numpy array to pandas dataframe 
Python :: how to remove python3 on mac 
Python :: how to replace a row value in pyspark dataframe 
Python :: how to use colorama 
Python :: python split tuples into lists 
Python :: get all combinations from two lists python 
Python :: reduce in python 
Python :: 1052 uri solution 
Python :: how to check if two columns match in pandas 
Python :: run python script from c# 
Python :: Static Assets in Django 
Python :: Resource punkt not found. Please use the NLTK Downloader to obtain the resource: 
Python :: how to use enumerate instead of range and len 
Python :: b1-motion tkinter 
Python :: frequency unique pandas 
Python :: export csv from dataframe python 
Python :: python list comprehension double for 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =