Skip to main content
Bumped by Community user
Bumped by Community user
added 3 characters in body
Source Link
Kam
  • 83
  • 2
  • 6

This is perhaps more of a coding question than data science so apologies if this is not the right platform to ask this.

My question is related to the sklearn's ColumnTransformer class. Considering 'description' corresponds to a text/string data column with 9508 rows. The following works as expected:

In [61]: transformer = ColumnTransformer(transformers=[('text-features', CountVectorizer(), 'description')])

In [62]: X=transformer.fit_transform(df)

In [63]: X.shape
Out[63]: (9508, 5913)

However, the following (note the [] around 'description'):

In [64]: transformer = ColumnTransformer(transformers=[('text-features', CountVectorizer(), ['description'])])

In [65]: X=transformer.fit_transform(df)

does not work as expected:

In [66]: X.shape
Out[66]: (1, 3)

Note that there is no issue parsing the list of column names for other transformers such as OneHotEncoder(). This is making it difficult to programmatically configure transformers for dataframes containing heterogenous data type columns.

One possibility is to configure transformer for each column individually even if multiple columns require the same transformer but I was wondering if there is better way to deal with this?

This is perhaps more of a coding question than data science so apologies if this is not the right platform to ask this.

My question is related to the sklearn's ColumnTransformer class. Considering 'description' corresponds to a text/string data column with 9508 rows. The following works as expected:

In [61]: transformer = ColumnTransformer(transformers=[('text-features', CountVectorizer(), 'description')])

In [62]: X=transformer.fit_transform(df)

In [63]: X.shape
Out[63]: (9508, 5913)

However, the following (note the [] around 'description'):

In [64]: transformer = ColumnTransformer(transformers=[('text-features', CountVectorizer(), ['description'])])

In [65]: X=transformer.fit_transform(df)

does not work as expected:

In [66]: X.shape
Out[66]: (1, 3)

Note that there is no issue parsing the list of column names for other transformers such as OneHotEncoder(). This is making it difficult to programmatically configure transformers for dataframes containing heterogenous data type columns.

One possibility to configure transformer for each column individually even if multiple columns require the same transformer but I was wondering if there is better way to deal with this?

This is perhaps more of a coding question than data science so apologies if this is not the right platform to ask this.

My question is related to the sklearn's ColumnTransformer class. Considering 'description' corresponds to a text/string data column with 9508 rows. The following works as expected:

In [61]: transformer = ColumnTransformer(transformers=[('text-features', CountVectorizer(), 'description')])

In [62]: X=transformer.fit_transform(df)

In [63]: X.shape
Out[63]: (9508, 5913)

However, the following (note the [] around 'description'):

In [64]: transformer = ColumnTransformer(transformers=[('text-features', CountVectorizer(), ['description'])])

In [65]: X=transformer.fit_transform(df)

does not work as expected:

In [66]: X.shape
Out[66]: (1, 3)

Note that there is no issue parsing the list of column names for other transformers such as OneHotEncoder(). This is making it difficult to programmatically configure transformers for dataframes containing heterogenous data type columns.

One possibility is to configure transformer for each column individually even if multiple columns require the same transformer but I was wondering if there is better way to deal with this?

Source Link
Kam
  • 83
  • 2
  • 6

Columntransformer multiple columns with vector inputs

This is perhaps more of a coding question than data science so apologies if this is not the right platform to ask this.

My question is related to the sklearn's ColumnTransformer class. Considering 'description' corresponds to a text/string data column with 9508 rows. The following works as expected:

In [61]: transformer = ColumnTransformer(transformers=[('text-features', CountVectorizer(), 'description')])

In [62]: X=transformer.fit_transform(df)

In [63]: X.shape
Out[63]: (9508, 5913)

However, the following (note the [] around 'description'):

In [64]: transformer = ColumnTransformer(transformers=[('text-features', CountVectorizer(), ['description'])])

In [65]: X=transformer.fit_transform(df)

does not work as expected:

In [66]: X.shape
Out[66]: (1, 3)

Note that there is no issue parsing the list of column names for other transformers such as OneHotEncoder(). This is making it difficult to programmatically configure transformers for dataframes containing heterogenous data type columns.

One possibility to configure transformer for each column individually even if multiple columns require the same transformer but I was wondering if there is better way to deal with this?