Issue
I'm trying to use OneHotEncoding on the categorical variables of the following dataset.
First, I'm trying to convert the 'Geography' column. Here's what I've done so far:
from sklearn.preprocessing import OneHotEncoder
from sklearn.compose import ColumnTransformer
ct = ColumnTransformer(['Geography',OneHotEncoder(categories='auto'),[1]],remainder='passthrough')
df_ = ct.fit_transform(df.values)
However, when I try this, I get the following error:
Can someone help me to understand why this error occurs and how to solve this?
Solution
There is a syntax error in the input parameter to the ColumnTransformer
. It expects a list of tuples.
transformers : list of tuples
List of (name, transformer, columns) tuples specifying the transformer objects to be applied to subsets of the data.
Try fixing it by converting the encoder params to a tuple
ct = ColumnTransformer([('Geography',OneHotEncoder(categories='auto'),[1])],remainder='passthrough')
Answered By - jdsurya
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.