Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

one hot encoder python

from sklearn.preprocessing import OneHotEncoder
encoder = OneHotEncoder()
# apply on df
color_1hot = encoder.fit_transform(df['ocean_proximity'].values.reshape(-1,1))
color_1hot_df = pd.DataFrame(color_1hot.toarray())
df = pd.concat([df.drop('ocean_proximity', axis=1), color_1hot_df], axis=1)
# can allso use the pandas dummies
df = pd.get_dummies(df, columns=['ocean_proximity'])

# apply on np.array
X[:, 2] = le.fit_transform(X[:, 2])
Comment

PREVIOUS NEXT
Code Example
Python :: calculate entropy 
Python :: how to factorise expressions in python 
Python :: python custom array sort 
Python :: python list group by count 
Python :: python pip fix 
Python :: python string to xml 
Python :: python open website 
Python :: how to end the python program 
Python :: how to make any player hit a ball using python turtle 
Python :: regex all words longer than n 
Python :: check version numpy 
Python :: python replace regex 
Python :: order dataframe by multiple columns python 
Python :: redirect django 
Python :: pandas combine two data frames with same index and same columns 
Python :: web scraping linkedin profiles python jupyter 
Python :: how to make all time greeter using python 
Python :: pandas query like 
Python :: how do I run a python program on atom 
Python :: python how to remove last letter from string 
Python :: python n choose r 
Python :: get list of users django 
Python :: all possible substring in python 
Python :: python find which os 
Python :: calcolatrice 
Python :: python change comma to dot 
Python :: How to make an simple python client 
Python :: python how to get every name in folder 
Python :: requests post with headers python 
Python :: python every other goes to a list 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =