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 version for python - 2.7, Scipy 0.16.0

, numpy 1.9.2+mkl

, scikit-learn 0.16.1

.

+3


source to share


1 answer


This means it was DictVectorizer

not installed before converting X_features

to the appropriate matrix format.



You need to call vec.fit(X_features)

and then vec.transform(X_features)

or more succintly X_test = vec.fit_transform(X_features)

. DictVectorizer

must know the keys of all past dictionaries so that converting the invisible data sequentially gives the same number of columns and the order of the columns.

+5


source







All Articles