如何根据精度和拟合设置机器学习算法的优先级以进行四元分类

数据挖掘 机器学习 机器学习模型 监督学习
2022-03-10 23:52:10

澳大利亚的降雨分类

在此背景下,将使用sklearn分类算法,即:

逻辑回归分类(参数) 决策树分类(非参数) 随机森林分类(非参数) K-最近邻(KNN)分类(非参数)

训练测试拆分为 80-20

准确度分数:

Logistic Regression Test Score     0.854062
Logistic Regression Train Score    0.853797

Decision Tree Test Score           0.795838
Decision Tree Train Score          1.000000

Random Forest Test Score           0.858269
Random Forest Train Score          0.999978

K-Nearest Neighbour Test Score     0.817180
K-Nearest Neighbour Train Score    0.831138

`Null accuracy score: 0.7815`

逻辑回归在没有overfitting. 但是如果看准确率,随机森林的准确率会更好。

如何检查underfitting

混淆矩阵

LR

DT

RR

神经网络

中华民国 AUC :

ROC AUC For LR : 0.8742

LR

ROC AUC For DT : 0.7072

DT

ROC AUC For RF : 0.8883

射频

ROC AUC For KNN : 0.7928

神经网络

分类指标

Classification accuracy : 0.8583
Classification error : 0.1417
Precision : 0.9586
Recall : 0.8726
True Positive Rate : 0.8726
False Positive Rate : 0.2286
Specificity : 0.7714

逻辑回归

             precision    recall  f1-score   support

          No       0.88      0.95      0.91     17650
         Yes       0.74      0.52      0.61      4935

    accuracy                           0.85     22585
   macro avg       0.81      0.73      0.76     22585
weighted avg       0.85      0.85      0.84     22585

决策树

           precision    recall  f1-score   support

          No       0.87      0.86      0.87     17650
         Yes       0.53      0.55      0.54      4935

    accuracy                           0.80     22585
   macro avg       0.70      0.71      0.70     22585
weighted avg       0.80      0.80      0.80     22585

随机森林分类

             precision    recall  f1-score   support

          No       0.87      0.96      0.91     17650
         Yes       0.77      0.50      0.61      4935

    accuracy                           0.86     22585
   macro avg       0.82      0.73      0.76     22585
weighted avg       0.85      0.86      0.85     22585

K-最近邻(KNN)分类

              precision    recall  f1-score   support

          No       0.84      0.95      0.89     17650
         Yes       0.66      0.34      0.45      4935

    accuracy                           0.82     22585
   macro avg       0.75      0.64      0.67     22585
weighted avg       0.80      0.82      0.79     22585

应仅对 Logistic 或对所有四个进行评估。

1个回答

由于您对 RF 部分过度拟合,因此首先尝试使 RF 超参数正确。您可以进行网格搜索,例如:

rf = RandomForestClassifier(...) 

param_grid = { 
    'n_estimators': [200,300],
    'max_features': [10,20,30]
}

cv = GridSearchCV(estimator=rf, param_grid=param_grid, cv= 5)
cv.fit(xtrain, ytrain)

并且特别感兴趣。更多的树 ( ) 往往“更好”。RandomForestClassifier max_depthmax_featuresn_estimators

(单)决策树通常不是一个好的估计器。

正确调整 RF 后,您还可以尝试“堆叠”KNN、逻辑回归和 RF,因为它们三者都不错。

Sklearn 自带了一个方便的堆叠功能,即StackingClassifier.