随机森林_处理不均衡数据

网友投稿 945 2022-11-16

随机森林_处理不均衡数据

随机森林_处理不均衡数据

随机森林_处理不均衡数据

balanced 加上balanced 参数

# 处理不均衡的数据from sklearn.ensemble import RandomForestClassifierfrom sklearn import datasetsfrom sklearn.feature_selection import SelectFromModeliris = datasets.load_iris()features = iris.datatarget = iris.target# 删除前40个features = features[40:, :]target = target[40:]# 二值化target = np.where((target == 0), 0, 1)# balanced 加上balanced 参数randomforest = RandomForestClassifier(random_state=0, n_jobs=-1, class_weight="balanced")# 训练模型 可设置权重值model = randomforest.fit(features, target)DiscussionA useful argument is balanced, wherein classes are automatically weighted inversely proptional to how frequently they appear in the data:wj=nknjwj=nknj where wjwj is the weight to class j, n is the number of observations, njnj is the number of observations in class j, and k is the total number of classes.

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:通过阈值筛选随机森林的重要特征
下一篇:Hadoop环境配置之hive环境配置详解
相关文章

 发表评论

暂时没有评论,来抢沙发吧~