机器学习4----随机森林

import numpy as np
import pandas as pd
from sklearn.datasets import load_iris
data,target=load_iris(return_X_y=True)
data.shape
data
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(data,target,test_size=0.2)
from sklearn.ensemble import RandomForestClassifier  
# n_estimators=100: 决策树的数量,默认100
# max_samples=None, : 最大样本数
#    - If None (default), then draw `X.shape[0]` samples.
#     - If int, then draw `max_samples` samples.
#     - If float, then draw `max_samples * X.shape[0]` samples. Thus,
#       `max_samples` should be in the interval `(0.0, 1.0]`.
# max_features='sqrt', : 最大特征数
#  - If int, then consider `max_features` features at each split.
#     - If float, then `max_features` is a fraction and
#       `max(1, int(max_features * n_features_in_))` features are considered at each
#       split.
#     - If "auto", then `max_features=sqrt(n_features)`.
#     - If "sqrt", then `max_features=sqrt(n_features)`.
#     - If "log2", then `max_features=log2(n_features)`.
#     - If None, then `max_features=n_features`.
# bootstrap=True, 有放回抽样,自助采样法
rfc=RandomForestClassifier(n_estimators=10,max_features=3,max_samples=100)
rfc.fit(x_train,y_train)
#### 特征重要性
rfc.feature_importances_
# 所有的子决策树
rfc.estimators_
# 遍历每一个子决策树
for m in rfc.estimators_:
    y_=m.predict(x_test)
    print(y_[:10])
rfc.predict(x_test)[:10]
rfc.score(x_train,y_train)
rfc.score(x_test,y_test)

相关推荐

  1. 机器学习随机森林算法

    2024-02-16 03:26:01       43 阅读
  2. 机器学习实验------随机森林

    2024-02-16 03:26:01       36 阅读
  3. 6、机器学习随机森林

    2024-02-16 03:26:01       58 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-16 03:26:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-16 03:26:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-02-16 03:26:01       82 阅读
  4. Python语言-面向对象

    2024-02-16 03:26:01       91 阅读

热门阅读

  1. 2024.02.11

    2024-02-16 03:26:01       50 阅读
  2. 「优选算法刷题」:除自身以外数组的乘积

    2024-02-16 03:26:01       61 阅读
  3. 算法刷题day12

    2024-02-16 03:26:01       58 阅读
  4. MySQL学习Day15——MySQL架构

    2024-02-16 03:26:01       48 阅读
  5. 奇异递归模板模式应用2-单例模板

    2024-02-16 03:26:01       58 阅读
  6. 2024/2/14

    2024-02-16 03:26:01       52 阅读
  7. Introduction to GraphQL-style APIs

    2024-02-16 03:26:01       45 阅读
  8. 在STM32微控制器中实现高速数据传输的DMA技巧

    2024-02-16 03:26:01       64 阅读
  9. 学习总结11

    2024-02-16 03:26:01       47 阅读
  10. 【30秒看懂大数据】数据标准

    2024-02-16 03:26:01       57 阅读