以下代码显示了在 SMOTE 生成的数据集上进行训练时,准确度和 roc_auc_score 是如何相同的。
sm = SMOTE(random_state = 2) #creating SMOTE object
X_t, y_t = sm.fit_sample(X, y) #fitting X and y in smote and storing the new dataset in X_t and y_t
clf_temp = LinearDiscriminantAnalysis()
clf_temp.fit(X_t,y_t)
y_score = clf_temp.predict(X_t)
print(accuracy_score(y_t,y_score))
print(roc_auc_score(y_t,y_score))
0.8015075376884422
0.8015075376884422
而在没有 SMOTE 的相同分类器上训练数据集时会给出不同的结果
clf_temp.fit(X,y)
y_score = clf_temp.predict(X)
print(accuracy_score(y,y_score))
print(roc_auc_score(y,y_score))
0.7996592361209712
0.7183922969169426