question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError: 'ColumnTransformer' object has no attribute '_check_n_features'

See original GitHub issue

I am a beginner and started learning data science some days ago. My feature data set has some categorical features and I was trying to preprocess in order to convert them into numbers. I was trying to use the ColumnTransformer from the sklearn compose module but had an error when I used the fit_transform( ) parameter>

# Turn our categories into numbers 

from sklearn.preprocessing import OneHotEncoder
from sklearn.compose import ColumnTransformer               

categorical_features = ["Make", "Colour", "Doors"]

one_hot = OneHotEncoder()

transformer = ColumnTransformer([("one_hot", 
                                  one_hot, 
                                  categorical_features)],
                                  remainder = "passthrough")
transformed_X= transformer.fit_transform(X)

These are the details of the error:

AttributeError                            Traceback (most recent call last)
<ipython-input-179-9955bb392ac9> in <module>
     12                                   categorical_features)],
     13                                   remainder = "passthrough")
---> 14 transformed_X= transformer.fit_transform(X)

~\Desktop\sample_project1\env\lib\site-packages\sklearn\compose\_column_transformer.py in fit_transform(self, X, y)
    524         X = _check_X(X)
    525         # set n_features_in_ attribute
--> 526         self._check_n_features(X, reset=True)
    527         self._validate_transformers()
    528         self._validate_column_callables(X)

AttributeError: 'ColumnTransformer' object has no attribute '_check_n_features'*

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
glemaitrecommented, Jun 26, 2020

So the original traceback shows some code from scikit-learn 0.23.1 while your import shows scikit-learn 0.22.1 which explains that there is something fishy.

Could you update/resinstall scikit-learn 0.23

0reactions
glemaitrecommented, Jun 29, 2020

Happy that it works closing

Read more comments on GitHub >

github_iconTop Results From Across the Web

'ColumnTransformer' object has no attribute 'transformers_ ...
I get this error when trying to get the list of transformers for a ColumnTransformer like this after the fit has been ...
Read more >
'columntransformer' object has no attribute '_feature_names_in'
Pipeline error: "AttributeError: 'ColumnTransformer' object has no attribute '_feature_names_in'". Asked Mar 5, 2020 • 2 votes 2 answers. QUESTION ANSWERS.
Read more >
sklearn.compose.ColumnTransformer
Convenience function for combining the outputs of multiple transformer objects applied to column subsets of the original feature space. make_column_selector.
Read more >
Convert a pipeline — sklearn-onnx 1.13 documentation
The error AttributeError: 'ColumnTransformer' object has no attribute 'transformers_' means the model was not trained. The converter tries to access an ...
Read more >
ColumnTransformer — sktime documentation
Simply takes the column transformer from sklearn and adds capability to handle ... named_transformers_ Bunch object, a dictionary with attribute access.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found