【发布时间】:2019-08-15 11:48:19
【问题描述】:
平均集成分类后,我得到了一个奇怪的混淆矩阵,甚至更奇怪的度量分数。
代码:-
x = data_train[categorical_columns + numerical_columns]
y = data_train['target']
from imblearn.over_sampling import SMOTE
x_sample, y_sample = SMOTE().fit_sample(x, y.values.ravel())
x_sample = pd.DataFrame(x_sample)
y_sample = pd.DataFrame(y_sample)
# checking the sizes of the sample data
print("Size of x-sample :", x_sample.shape)
print("Size of y-sample :", y_sample.shape)
# Train-Test split.
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(x_sample, y_sample,
test_size=0.40,
shuffle=False)
准确率为 99.9%,但召回率、f1-score 和准确率为 0。以前从未遇到过这个问题。我使用过 Adaboost 分类器。
Confusion Matrix for ADB:
[[46399 25]
[ 0 0]]
Accuracy for ADB:
0.9994614854385663
Precision for ADB:
0.0
Recall for ADB:
0.0
f1_score for ADB:
0.0
因为它是一个不平衡的数据集,所以我使用了 SMOTE。现在我得到的结果如下:
Confusion Matrix for ETC:
[[ 0 0]
[ 336 92002]]
Accuracy for ETC:
0.99636119474106
Precision for ETC:
1.0
Recall for ETC:
0.99636119474106
f1_score for ETC:
0.9981772811109906
【问题讨论】:
-
请注意,您在样本上使用了 smote - 然后将其拆分为训练和测试。您首先需要将其拆分为训练和测试,然后才在训练数据上使用 SMOTE。
-
做到了。但仍然像 ADB 的混淆矩阵:[[46399 25] [0 0]] ADB 的准确度:0.9994614854385663 ADB 的精度:0.0 ADB 的召回率:0.0 ADB 的 f1_score:0.0
-
您还可以分享训练数据上的混淆矩阵吗?可能 Adaboost 过度拟合,需要另一种技术。
-
所有技术的混淆矩阵都像 adaboost 展示的那样来了
标签: machine-learning scikit-learn metrics