You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ColumnTransformer has an option remainder="drop" (which is the default) that makes it drop any column from the input that is not handled within the transformers passed to its transformers (list) argument.
However, if the data to which the ColumnTransformer is fitted is a DataFrame with named columns, and there are columns which end up dropped due to not being handled by the transformer, these columns are still required to be in the DataFrame when calling transform, which shouldn't be.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1-3b20260b9d3f> in <module>
14 ], remainder="drop")
15 ct.fit(df, df["col3"])
---> 16 ct.transform(df[["col1", "col2"]])
~/ipython/del/sklearn/compose/_column_transformer.py in transform(self, X)
555 X_feature_names = None
556
--> 557 self._check_n_features(X, reset=False)
558 if (self._feature_names_in is not None and
559 X_feature_names is not None and
~/ipython/del/sklearn/base.py in _check_n_features(self, X, reset)
364 if n_features != self.n_features_in_:
365 raise ValueError(
--> 366 f"X has {n_features} features, but {self.__class__.__name__} "
367 f"is expecting {self.n_features_in_} features as input.")
368
ValueError: X has 2 features, but ColumnTransformer is expecting 3 features as input.
In this case, the transformer will only take columns col1 and col2, but still demands that the input have col3 which is not used.
The text was updated successfully, but these errors were encountered:
The
ColumnTransformer
has an optionremainder="drop"
(which is the default) that makes it drop any column from the input that is not handled within the transformers passed to itstransformers
(list) argument.However, if the data to which the
ColumnTransformer
is fitted is aDataFrame
with named columns, and there are columns which end up dropped due to not being handled by the transformer, these columns are still required to be in theDataFrame
when callingtransform
, which shouldn't be.Example:
In this case, the transformer will only take columns
col1
andcol2
, but still demands that the input havecol3
which is not used.The text was updated successfully, but these errors were encountered: