首页 > 解决方案 > 处理不平衡的类 SMOTE,仍然没有得到很好的结果

问题描述

我有一个目标变量分布的数据集:

类别=3,百分比=15.235%
类别=2,百分比= 2.471%
类别=1,百分比=42.964%
类别=0,百分比=39.330%

看到有一个不平衡的数据集,我决定使用 SMOTE 来平衡数据集。

cls = {0:.43, 1:.30, 2:.02,3:.20}
classifier = RandomForestClassifier
    
# build model with SMOTE imblearn

smote_pipeline = make_pipeline_imb(SMOTE(random_state=42), \
                                   classifier(random_state=42, class_weight = cls))

smote_model = smote_pipeline.fit(X_train, Y_train)
smote_prediction = smote_model.predict(X_test)

#Showing the diference before and after the transformation used
print("normal data distribution: {}".format(Counter(y)))
oversample = SMOTE()
X_smote, y_smote = oversample.fit_resample(X, y)
print("SMOTE data distribution: {}".format(Counter(y_smote)))

print('accuracy %s' % accuracy_score(smote_prediction, Y_test))
print(classification_report(Y_test, smote_prediction))

这是输出:
在此处输入图像描述

问题:即使在执行了 Smote 并设置了类权重之后,结果似乎也不太准确。我犯了什么错误导致结果没有按预期执行?与 0 类和 1 类相比,2 类和 3 类主要是相当低的。

标签: pythonscikit-learnrandom-forestimbalanced-datasmote

解决方案


推荐阅读