【问题标题】:I have done a classification problem where I am getting 99.9% accuracy but precision,recall,f1 is coming 0我已经完成了一个分类问题,我得到了 99.9% 的准确率,但准确率、召回率、f1 为 0
【发布时间】: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


【解决方案1】:

发生这种情况是因为您有不平衡的数据集 (99.9% 0's and only 0.1% 1's)。在这种情况下,使用准确性作为度量可能会产生误导。

您可以阅读更多关于在这种情况下使用哪些指标的here

【讨论】:

    【解决方案2】:

    上述答案中提到的HI是因为偏斜(不平衡的数据)。但是,我想提供一个更简单的解决方案。使用 SVM。

    model = sklearn.svm.SVC(class_weight = 'balanced')
    model.fit(X_train, y_train)
    
    

    使用平衡的 class_weight 将自动赋予所有类同等的重要性,而与数据集中每个类的数据点数量无关。此外,在 SVM 中使用“rbf”内核会提供非常好的准确性。

    【讨论】:

      猜你喜欢
      • 2016-04-14
      • 2020-06-29
      • 2020-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-06
      • 1970-01-01
      • 2019-07-28
      相关资源
      最近更新 更多