【发布时间】:2019-07-26 22:34:28
【问题描述】:
我正在使用 StratifiedKFold 来检查我的分类器的性能。我有两个班级,我试图建立 Logistic Regression classier。 这是我的代码
skf = StratifiedKFold(n_splits=10, shuffle=True, random_state=0)
for train_index, test_index in skf.split(x, y):
x_train, x_test = x[train_index], x[test_index]
y_train, y_test = y[train_index], y[test_index]
tfidf = TfidfVectorizer()
x_train = tfidf.fit_transform(x_train)
x_test = tfidf.transform(x_test)
clf = LogisticRegression(class_weight='balanced')
clf.fit(x_train, y_train)
y_pred = clf.predict(x_test)
score = accuracy_score(y_test, y_pred)
r.append(score)
print(score)
print(np.mean(r))
我可以只打印性能分数,但我不知道如何打印混淆矩阵和分类报告。如果我只是在循环内添加打印语句,
print(confusion_matrix(y_test, y_pred))
它会打印 10 次,但我想报告分类器最终性能的矩阵。
关于如何计算矩阵和报告的任何帮助。谢谢
【问题讨论】:
-
欢迎来到 SO;请发布您迄今为止尝试过的内容以及您面临的具体问题 - 事实上,即使是非常基本的内容(例如,有多少个课程?),您也没有提供任何有用的信息(例如,有多少个课程?)
-
对不起,我会编辑帖子
标签: python machine-learning scikit-learn confusion-matrix