Issue
I'm trying to use OneHotEncoding on the categorical variables of the following dataset.
src="https://i.stack.imgur.com/9o9qP.png" alt="enter image description here" />
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 Answer Checked By - David Goodson (Python.Easybugfix Volunteer)
Post a Comment
Post a Comment