sklearn随机森林的参数有哪些

发布时间:2022-03-22 10:11:28 作者:iii
来源:亿速云 阅读:256

这篇文章主要介绍“sklearn随机森林的参数有哪些”,在日常操作中,相信很多人在sklearn随机森林的参数有哪些问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”sklearn随机森林的参数有哪些”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

随机森林


      随机森林是一个元估计器,它适合数据集的各个子样本上的多个决策树分类器,并使用平均值来提高预测精度和控制过度拟合。子样本大小始终与原始输入样本大小相同,但如果bootstrap = True(默认值),则会使用替换来绘制样本。
先看这个类的参数:

class sklearn.ensemble.RandomForestClassifier(n_estimators=10, criterion='gini', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=’auto’, max_leaf_nodes=None, min_impurity_decrease=0.0, min_impurity_split=None, bootstrap=True, oob_score=False, n_jobs=1, random_state=None, verbose=0, warm_start=False, class_weight=None)

代码举例:

from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_classification

X, y = make_classification(n_samples=1000, n_features=4,
                           n_informative=2, n_redundant=0,
                           random_state=0, shuffle=False)
clf = RandomForestClassifier(max_depth=2, random_state=0)
clf.fit(X, y)
RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
           max_depth=2, max_features='auto', max_leaf_nodes=None,
           min_impurity_decrease=0.0, min_impurity_split=None,
           min_samples_leaf=1, min_samples_split=2,
           min_weight_fraction_leaf=0.0, n_estimators=10, n_jobs=1,
           oob_score=False, random_state=0, verbose=0, warm_start=False)
print(clf.feature_importances_)
[ 0.17287856  0.80608704  0.01884792  0.00218648]
print(clf.predict([[0, 0, 0, 0]]))
[1]

具体参数意义如下:
参数:

属性:

注意点:

参数的默认值控制决策树的大小(例如,max_depth,,min_samples_leaf等等),导致完全的生长和在某些数据集上可能非常大的未修剪的树。为了降低内容消耗,决策树的复杂度和大小应该通过设置这些参数值来控制。

这些特征总是在每个分割中随机排列。 因此,即使使用相同的训练数据,max_features = n_features和bootstrap = False,如果在搜索最佳分割期间所列举的若干分割的准则的改进是相同的,那么找到的最佳分割点可能会不同。为了在拟合过程中获得一个确定的行为,random_state将不得不被修正。

方法:

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.

到此,关于“sklearn随机森林的参数有哪些”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

推荐阅读:
  1. predictionio 随机森林
  2. pyspark如何实现随机森林

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

sklearn

上一篇:python如何使用库

下一篇:js如何使用typeof

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》