sklearn 随机森林方法

Notes

The default values for the parameters controlling the size of the trees (e.g. max_depth, min_samples_leaf, etc.) lead to fully grown and unpruned trees which can potentially be very large on some data sets. To reduce memory consumption, the complexity and size of the trees should be controlled by setting those parameter values.

The features are always randomly permuted at each split. Therefore, the best found split may vary, even with the same training data, max_features=n_features and bootstrap=False, if the improvement of the criterion is identical for several splits enumerated during the search of the best split. To obtain a deterministic behaviour during fitting, random_state has to be fixed.

References

[R157]
Breiman, “Random Forests”, Machine Learning, 45(1), 5-32, 2001.

Methods

apply(X) Apply trees in the forest to X, return leaf indices.
decision_path(X) Return the decision path in the forest
fit(X, y[, sample_weight]) Build a forest of trees from the training set (X, y).
get_params([deep]) Get parameters for this estimator.
predict(X) Predict class for X.
predict_log_proba(X) Predict class log-probabilities for X.
predict_proba(X) Predict class probabilities for X.
score(X, y[, sample_weight]) Returns the mean accuracy on the given test data and labels.
set_params(**params) Set the parameters of this estimator.
predict(X)

Predict class for X.

The predicted class of an input sample is a vote by the trees in the forest, weighted by their probability estimates. That is, the predicted class is the one with highest mean probability estimate across the trees.

Parameters:
X : array-like or sparse matrix of shape = [n_samples, n_features]

The input samples. Internally, its dtype will be converted to dtype=np.float32. If a sparse matrix is provided, it will be converted into a sparse csr_matrix.

Returns:
y : array of shape = [n_samples] or [n_samples, n_outputs]

The predicted classes.

predict_log_proba(X)

Predict class log-probabilities for X.

The predicted class log-probabilities of an input sample is computed as the log of the mean predicted class probabilities of the trees in the forest.

Parameters:
X : array-like or sparse matrix of shape = [n_samples, n_features]

The input samples. Internally, its dtype will be converted to dtype=np.float32. If a sparse matrix is provided, it will be converted into a sparse csr_matrix.

Returns:
p : array of shape = [n_samples, n_classes], or a list of n_outputs

such arrays if n_outputs > 1. The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.

predict_proba(X)

Predict class probabilities for X.

The predicted class probabilities of an input sample are computed as the mean predicted class probabilities of the trees in the forest. The class probability of a single tree is the fraction of samples of the same class in a leaf.

Parameters:
X : array-like or sparse matrix of shape = [n_samples, n_features]

The input samples. Internally, its dtype will be converted to dtype=np.float32. If a sparse matrix is provided, it will be converted into a sparse csr_matrix.

Returns:
p : array of shape = [n_samples, n_classes], or a list of n_outputs

such arrays if n_outputs > 1. The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.

score(Xysample_weight=None)

Returns the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters:
X : array-like, shape = (n_samples, n_features)

Test samples.

y : array-like, shape = (n_samples) or (n_samples, n_outputs)

True labels for X.

sample_weight : array-like, shape = [n_samples], optional

Sample weights.

Returns:
score : float

Mean accuracy of self.predict(X) wrt. y.

From Sklearn:

http://sklearn.apachecn.org/cn/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html#sklearn.ensemble.RandomForestClassifier

原文地址:https://www.cnblogs.com/Allen-rg/p/9577848.html

时间: 2024-08-09 18:10:18

sklearn 随机森林方法的相关文章

使用基于Apache Spark的随机森林方法预测贷款风险

使用基于Apache Spark的随机森林方法预测贷款风险 原文:Predicting Loan Credit Risk using Apache Spark Machine Learning Random Forests 作者:Carol McDonald,MapR解决方案架构师 翻译:KK4SBB 责编:周建丁([email protected].NET) 在本文中,我将向大家介绍如何使用Apache Spark的Spark.ml库中的随机森林算法来对银行信用贷款的风险做分类预测.Spark

解决sklearn 随机森林数据不平衡的方法

Handle Imbalanced Classes In Random Forest Preliminaries # Load libraries from sklearn.ensemble import RandomForestClassifier import numpy as np from sklearn import datasets Load Iris Flower Dataset # Load data iris = datasets.load_iris() X = iris.da

基于随机森林的煤与瓦斯突出预测方法研究

1引言 煤炭在我国一次能源中的主导地位短期内不会发生根本性改变.随着煤炭产量的增长,近年来我国煤矿生产事故频繁发生,安全形势非常严峻.煤矿事故已经成为社会各界关注的焦点.而煤与瓦斯突出是煤矿生产过程中的一种严重自然灾害.长期以来,煤与瓦斯突出事故严重制约着我国煤矿生产和煤炭企业经济效益的提高,给煤矿安全生产和井下作业人员的生命财产安全带来了极大威胁.因此,正确预测矿井煤与瓦斯突出的规模,对于煤炭企业安全生产具有重要的现实意义. 目前关于煤与瓦斯突出的预测方法主要有:单项指标法.瓦斯地质统计法.D

决策树-预测隐形眼镜类型 (ID3算法,C4.5算法,CART算法,GINI指数,剪枝,随机森林)

1. 1.问题的引入 2.一个实例 3.基本概念 4.ID3 5.C4.5 6.CART 7.随机森林 2. 我们应该设计什么的算法,使得计算机对贷款申请人员的申请信息自动进行分类,以决定能否贷款? 一个女孩的母亲要给这个女孩介绍男朋友,于是有了下面的对话: 女儿:多大年纪了? 母亲:26. 女儿:长的帅不帅? 母亲:挺帅的. 女儿:收入高不? 母亲:不算很高,中等情况. 女儿:是公务员不? 母亲:是,在税务局上班呢. 女儿:那好,我去见见. 决策过程: 这个女孩的决策过程就是典型的分类树决策.

随机森林入门攻略(内含R、Python代码)

随机森林入门攻略(内含R.Python代码) 简介 近年来,随机森林模型在界内的关注度与受欢迎程度有着显著的提升,这多半归功于它可以快速地被应用到几乎任何的数据科学问题中去,从而使人们能够高效快捷地获得第一组基准测试结果.在各种各样的问题中,随机森林一次又一次地展示出令人难以置信的强大,而与此同时它又是如此的方便实用. 需要大家注意的是,在上文中特别提到的是第一组测试结果,而非所有的结果,这是因为随机森林方法固然也有自己的局限性.在这篇文章中,我们将向你介绍运用随机森林构建预测模型时最令人感兴趣

机器学习——随机森林算法及原理

1. 随机森林使用背景 1.1 随机森林定义 随机森林是一种比较新的机器学习模型.经典的机器学习模型是神经网络,有半个多世纪的历史了.神经网络预测精确,但是计算量很大.上世纪八十年代Breiman等人发明分类树的算法(Breiman et al. 1984),通过反复二分数据进行分类或回归,计算量大大降低.2001年Breiman把分类树组合成随机森林(Breiman 2001a),即在变量(列)的使用和数据(行)的使用上进行随机化,生成很多分类树,再汇总分类树的结果.随机森林在运算量没有显著提

sklearn之随机森林

''' 集合算法: 1.正向激励 2.自助聚合:每次从总样本矩阵中以有放回抽样的方式随机抽取部分样本构建决策树,这样形成多棵包含不同训练样本的决策树, 以削弱某些强势样本对模型预测结果的影响,提高模型的泛化特性. 3.随机森林:在自助聚合的基础上,每次构建决策树模型时,不仅随机选择部分样本,而且还随机选择部分特征,这样的集合算法, 不仅规避了强势样本对预测结果的影响,而且也削弱了强势特征的影响,使模型的预测能力更加泛化.(中庸-->真值) 随机森林相关API: import sklearn.en

机器学习实战之 第七章 集成方法(随机森林和 AdaBoost)

第7章 集成方法 ensemble method 集成方法: ensemble method(元算法: meta algorithm) 概述 概念:是对其他算法进行组合的一种形式. 通俗来说: 当做重要决定时,大家可能都会考虑吸取多个专家而不只是一个人的意见. 机器学习处理问题时又何尝不是如此? 这就是集成方法背后的思想. 集成方法: 投票选举(bagging: 自举汇聚法 bootstrap aggregating): 是基于数据随机重抽样分类器构造的方法 再学习(boosting): 是基于

R语言基于树的方法:决策树,随机森林,套袋Bagging,增强树

原文链接:http://tecdat.cn/?p=9859 概观 本文是有关  基于树的  回归和分类方法的.用于分割预测变量空间的分割规则可以汇总在树中,因此通常称为  决策树  方法. 树方法简单易懂,但对于解释却非常有用,但就预测准确性而言,它们通常无法与最佳监督学习方法竞争.因此,我们还介绍了装袋,随机森林和增强.这些示例中的每一个都涉及产生多个树,然后将其合并以产生单个共识预测.我们看到,合并大量的树可以大大提高预测准确性,但代价是损失解释能力. 决策树可以应用于回归和分类问题.我们将