RandomForest icon indicating copy to clipboard operation
RandomForest copied to clipboard

模型预测结果不正确

Open zgkom opened this issue 4 years ago • 8 comments

我使用其他的数据集,无论是使用全部特征还是sqrt求出的特征,又或者是使用全部特征的单个决策树,预测结果都很差,尤其是训练集作为测试集,预测只有60%多。 参数: clf = RandomForestClassifier(n_estimators=1, max_depth=-1, min_samples_split=2, min_samples_leaf=1, min_split_gain=0.0, colsample_bytree=70, subsample=1.0, random_state=66) train_count = int(0.7 * len(df)) 下面是预测的结果。 0.6125 0.2375

zgkom avatar Mar 03 '20 04:03 zgkom

你设置的参数问题很大。 n_estimators:一棵决策树不够,设置10以上; min_samples_split:建议设置1/10len(df) min_samples_leaf:建议设置1/40len(df) colsample_bytree:可取[sqrt、log2]

zhaoxingfeng avatar Mar 03 '20 05:03 zhaoxingfeng

还是不行,我使用的数据集,正类830个,负类830个,70维。 clf = RandomForestClassifier(n_estimators=100, max_depth=-1, min_samples_split=160, min_samples_leaf=40, min_split_gain=0.0, colsample_bytree="sqrt", subsample=0.8, random_state=66) 预测训练集: 0.5133928571428571 预测测试集: 0.46875

同样的参数(sklearn库中的随机森林): clf = RandomForestClassifier(n_estimators=100,min_samples_split=160, min_samples_leaf=40) 预测训练集: precision recall f1-score support 0.0 1.00 1.00 1.00 446 1.0 1.00 1.00 1.00 674 预测测试集: precision recall f1-score support 0.0 1.00 1.00 1.00 176 1.0 1.00 1.00 1.00 304

唯一让我很疑惑的是,为什么训练集作为测试集的时候,随机森林预测准确度还不是100%。 另外查看代码的时候,我发现你计算gini系数是算的离散的值的概率,是不是需要使用连续值计算概率(大于或者小于分裂值)

zgkom avatar Mar 04 '20 09:03 zgkom

麻烦发一下样本集。

zhaoxingfeng avatar Mar 04 '20 11:03 zhaoxingfeng

非常感谢,已发送 [email protected] 邮箱,请注意查收。

zgkom avatar Mar 04 '20 14:03 zgkom

1、我看了你邮件发我的数据,对前70个特征分别画了label=0/1的分布,下图是前60个特征,分布非常接近 说明特征几乎没有区分度。 2、我用sklearn的随机森林测试,只设置n_estimators=100,训练集acc<60%,测试集acc<15%,得不到你说的准确率=100%的结论。 3、训练集作为测试集,准确率达不到100%是正常的,我们更关注的是测试集的表现,所以为了防止过拟合都会把训练集调的稍微欠拟合一点。 4、gini系数计算部分没有发现问题。 features_1 features_2

zhaoxingfeng avatar Mar 05 '20 01:03 zhaoxingfeng

非常感谢,我重新验证了一下自己的python程序,发现了我程序中的bug。 由于我个人失误,给您添了不少麻烦,十分抱歉。━┳━ ━┳━

zgkom avatar Mar 05 '20 03:03 zgkom

可视化图请问是如何实现的?谢谢

SihanMA avatar Jul 01 '21 16:07 SihanMA

@SihanMA 用的是seaborn可视化库

zhaoxingfeng avatar Jul 06 '21 10:07 zhaoxingfeng