04-12 scikit-learn库之随机森林

时间:2019-10-16 18:31:51   收藏:0   阅读:49

更新、更全的《机器学习》的更新网站,更有python、go、数据结构与算法、爬虫、人工智能教学等着你:https://www.cnblogs.com/nickchen121/

scikit-learn库之随机森林

本文主要介绍随机森林的两个模型RandomForestClassifierRandomForestRegressor,这两个模型调参包括两部分,第一部分是Bagging框架,第二部分是CART决策树的参数。本文会详解介绍RandomForestClassifier模型,然后会对比着讲解RandomForestRegressor模型。

接下来将会讨论上述两者的区别,由于是从官方文档翻译而来,翻译会略有偏颇,有兴趣的也可以去scikit-learn官方文档查看https://scikit-learn.org/stable/modules/classes.html#module-sklearn.ensemble

一、RandomForestClassifier

1.1 使用场景

RandomForestClassfier模型主要解决分类问题,其他也没啥好说的。

1.2 代码

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(n_estimators=100, 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=100, n_jobs=None,
            oob_score=False, random_state=0, verbose=0, warm_start=False)
print(clf.feature_importances_)
[0.14205973 0.76664038 0.0282433  0.06305659]
print(clf.predict([[0, 0, 0, 0]]))
[1]

1.3 参数

1.4 属性

1.5 方法

二、RandomForestRegressor

RandomForestRegressor模型相比较RandomForestClassifier模型解决回归问题。

原文:https://www.cnblogs.com/nickchen121/p/11686759.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!