Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sklearn feature.Extraction 'DictVectorizer' object has no attribute 'feature_names_'

Whenever I call transform it keeps giving me the following error :

AttributeError:'DictVectorizer' object has no attribute 'feature_names_'

This is the function call:

vec = DictVectorizer()
x_test = vec.transform(X_features)

My python version is 2.7, Scipy 0.16.0, numpy 1.9.2+mkl, scikit-learn 0.16.1.

like image 436
Tsaleem Avatar asked Mar 15 '23 06:03

Tsaleem


1 Answers

This means, that the DictVectorizer was not fitted prior to transforming X_features into it's corresponding matrix format.

You need to call vec.fit(X_features) followed by vec.transform(X_features), or more succintly X_test = vec.fit_transform(X_features). DictVectorizer needs to know the keys of all the passed dictionaries, so that the transformation of unseen data consistently yields the same number of columns and column order.

like image 161
Matt Avatar answered Apr 07 '23 09:04

Matt