我今天刚构建了我的第一个随机森林分类器,并且正在尝试提高其性能。我阅读了关于如何使用交叉验证来避免数据过拟合并获得更好结果的文章。我使用了sklearn中的StratifiedKFold方法实现了交叉验证,但令人惊讶的是,这种方法的准确性反而较低。我已经阅读了很多帖子,建议使用交叉验证比train_test_split更有效。
评估器:
以下是结果:
CV:
评估器:
rf = RandomForestClassifier(n_estimators=100, random_state=42)
K-Fold:
ss = StratifiedKFold(n_splits=10, shuffle=True, random_state=42)
for train_index, test_index in ss.split(features, labels):
train_features, test_features = features[train_index], features[test_index]
train_labels, test_labels = labels[train_index], labels[test_index]
TTS:
train_feature, test_feature, train_label, test_label = \
train_test_split(features, labels, train_size=0.8, test_size=0.2, random_state=42)
以下是结果:
CV:
AUROC: 0.74
Accuracy Score: 74.74 %.
Specificity: 0.69
Precision: 0.75
Sensitivity: 0.79
Matthews correlation coefficient (MCC): 0.49
F1 Score: 0.77
TTS:
AUROC: 0.76
Accuracy Score: 76.23 %.
Specificity: 0.77
Precision: 0.79
Sensitivity: 0.76
Matthews correlation coefficient (MCC): 0.52
F1 Score: 0.77
这真的可能吗?还是我错误地设置了我的模型?
此外,这是使用交叉验证的正确方式吗?