I’m using this exact snippet from Q14 but get an error. I don’t know why, especially that the first line says fit. I tried to get rid of target parameter - same thing happens. I also copied suggested answer from the previous exercises to make sure that every thing is all right. Any clue?
preprocessor.fit(data, target)
feature_names = (preprocessor.named_transformers_["onehotencoder"]
.get_feature_names(categorical_columns)).tolist()
feature_names += numerical_columns
feature_names
---------------------------------------------------------------------------
NotFittedError Traceback (most recent call last)
<ipython-input-11-4a32008c25d3> in <module>
----> 1 feature_names = (preprocessor.named_transformers_["onehotencoder"]
2 .get_feature_names(categorical_columns)).tolist()
3 feature_names += numerical_columns
4 feature_names
/opt/conda/lib/python3.9/site-packages/sklearn/preprocessing/_encoders.py in get_feature_names(self, input_features)
626 Array of feature names.
627 """
--> 628 check_is_fitted(self)
629 cats = self.categories_
630 if input_features is None:
/opt/conda/lib/python3.9/site-packages/sklearn/utils/validation.py in inner_f(*args, **kwargs)
61 extra_args = len(args) - len(all_args)
62 if extra_args <= 0:
---> 63 return f(*args, **kwargs)
64
65 # extra_args > 0
/opt/conda/lib/python3.9/site-packages/sklearn/utils/validation.py in check_is_fitted(estimator, attributes, msg, all_or_any)
1096
1097 if not attrs:
-> 1098 raise NotFittedError(msg % {'name': type(estimator).__name__})
1099
1100
NotFittedError: This OneHotEncoder instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator.