私は scikit-learn を使用していくつかのテキストで練習しています。
GridSearch に慣れるために、ここにあるサンプル コードから始めます。
###############################################################################
# define a pipeline combining a text feature extractor with a simple
# classifier
pipeline = Pipeline([
('vect', CountVectorizer())
])
parameters = {
'vect__max_df': (0.5, 0.75, 1.0)
}
grid_search.fit(X_train, y_train)
print("Best score: %0.3f" % grid_search.best_score_)
ここでは非常に注意を払っていることに注意してください。推定器とパラメーターは 1 つしかありません。
これを実行すると、次のエラーが表示されることがわかりました。
TypeError: If no scoring is specified, the estimator passed should have a 'score' method. The estimator Pipeline(steps=[('vect', CountVectorizer(analyzer=u'word', binary=False, decode_error=u'strict',
dtype=<type 'numpy.int64'>, encoding=u'utf-8', input=u'content',
lowercase=True, max_df=1.0, max_features=None, min_df=1,
ngram_range=(1, 1), preprocessor=None, stop_words=None,
strip_accents=None, token_pattern=u'(?u)\\b\\w\\w+\\b',
tokenizer=None, vocabulary=None))]) does not.
うーん...「スコア」属性が欠落しているのはなぜですか?
可能なパラメータを確認すると、
print CountVectorizer().get_params().keys()
この回答で暗示されているように、得点できるものは何もありません。
ドキュメントにはBy default, parameter search uses the score function of the estimator to evaluate a parameter setting.
、なぜスコアメソッドを指定する必要があるのですか?
とにかく、引数を明示的に渡す必要があるかもしれないと思ったのですがscoring
、これは役に立たず、エラーが発生しました: grid_search.fit(X_train, y_train, scoring=None)
このエラーがわかりません!