我使用GridSearchCV這樣的:sklearn GridSearchCV:如何獲取分類報告?
corpus = load_files('corpus')
with open('stopwords.txt', 'r') as f:
stop_words = [y for x in f.read().split('\n') for y in (x, x.title())]
x = corpus.data
y = corpus.target
pipeline = Pipeline([
('vec', CountVectorizer(stop_words=stop_words)),
('classifier', MultinomialNB())])
parameters = {'vec__ngram_range': [(1, 1), (1, 2)],
'classifier__alpha': [1e-2, 1e-3],
'classifier__fit_prior': [True, False]}
gs_clf = GridSearchCV(pipeline, parameters, n_jobs=-1, cv=5, scoring="f1", verbose=10)
gs_clf = gs_clf.fit(x, y)
joblib.dump(gs_clf.best_estimator_, 'MultinomialNB.pkl', compress=1)
然後,在另一個文件中,新的文件進行分類(不是從陰莖),我這樣做:
classifier = joblib.load(filepath) # path to .pkl file
result = classifier.predict(tokenlist)
我的問題是:在哪裏我得到了classification_report
所需的值?
在許多其他的例子中,我看到人們將語料庫分成traing集和測試集。 但是,由於我使用了使用kfold-cross-validation的GridSearchCV
,因此我不需要那樣做。 那麼如何從GridSearchCV
獲得這些值?
只是一個問題,不'gs_clf.fit(X,Y )'return'None'? – BallpointBen
@BallpointBen爲什麼會這樣? x和y包含數據 – user3813234