Issue
I am trying to run this combined model, of text and numeric features, and I am getting the error ValueError: Invalid parameter tfidf for estimator
. Is the problem in the parameters
synthax?
Possibly helpful links:
FeatureUnion usage
FeatureUnion documentation
tknzr = tokenize.word_tokenize
vect = CountVectorizer(tokenizer=tknzr, stop_words={'english'}, max_df=0.9, min_df=2)
scl = StandardScaler(with_mean=False)
tfidf = TfidfTransformer(norm=None)
parameters = {
'vect__ngram_range': [(1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (3, 3)],
'tfidf__use_idf': (True, False),
'clf__alpha': tuple(10 ** (np.arange(-4, 4, dtype='float'))),
'clf__loss': ('hinge', 'squared_hinge', 'log', 'modified_huber', 'perceptron'),
'clf__penalty': ('l1', 'l2'),
'clf__tol': (1e07, 1e-6, 1e-5, 1e-4, 1e-3)
}
combined_clf = Pipeline([
('features', FeatureUnion([
('numeric_features', Pipeline([
('selector', transfomer_numeric)
])),
('text_features', Pipeline([
('selector', transformer_text),
('vect', vect),
('tfidf', tfidf),
('scaler', scl),
]))
])),
('clf', SGDClassifier(random_state=42,
max_iter=int(10 ** 6 / len(X_train)), shuffle=True))
])
Solution
As stated here, nested parameters must be accessed by the __
(double underscore) syntax. Depending on the depth of the parameter you want to access, this applies recursively. The parameter use_idf
is under:
features
> text_features
> tfidf
> use_idf
So the resulting parameter in your grid needs to be:
'features__text_features__tfidf__use_idf': [True, False]
Similarly, the syntax for ngram_range
should be:
'features__text_features__vect__ngram_range': [(1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (3, 3)]
Answered By - afsharov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.