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
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With