# Author: Leao
# Time: 2020.10.9
# 随机森林是一种集成学习算法, 可集成指定树的数量,有参数n_estimators
import sklearn
sklearn.__version__
sklearn.__name__
sklearn.__package__
dir(sklearn)
from sklearn import ensemble
dir(ensemble)
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split # 数据分割
from sklearn.datasets import load_wine #红酒数据集
# Load wine dataset加载红酒数据集
wine = load_wine()
wine.data
wine.data.shape
wine.target
wine.target.shape
# data split 红酒数据集分割
X_train, X_test, y_train, y_test = train_test_split(wine.data, wine.target, test_size=0.3)
# Model模型
dtc = DecisionTreeClassifier(random_state=0) # 决策树分类
sklearn 随机森林_随机森林Random Forest
最新推荐文章于 2023-12-19 18:05:55 发布
本文介绍了如何利用Python中的sklearn库构建和应用随机森林模型,涵盖了从数据预处理到模型训练、评估的全过程。
摘要由CSDN通过智能技术生成