이 같은 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
에 필요한 값을 얻었습니까?
다른 많은 예에서 사람들이 코퍼스를 트래킹 세트와 테스트 세트로 나눕니다. 그러나 kfold-cross-validation과 함께 GridSearchCV
을 사용하고 있으므로이 작업을 수행 할 필요가 없습니다. 그런 값을 GridSearchCV
에서 어떻게 얻을 수 있습니까?
그냥 질문은하지'gs_clf.fit (X, Y를 수행)'return'None'? – BallpointBen
@BallpointBen 왜 그럴까요? x와 y에는 데이터가 포함되어 있습니다 – user3813234