sklearn 实现随机森林分类器 - python 实现

python sklearn 实现随机森林分类器

python 复制代码
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_iris
# 加载数据集
iris=load_iris()
x,y=iris.data,iris.target
print("x y shape:",x.shape,y.shape)
# 创建并训练模型
model = RandomForestClassifier(
    n_estimators = 10,
    )
model.fit(x,y)# 模型训练

# 保存模型
from joblib import dump
dump(model, 'random_forest_model.joblib')# 模型保存

from joblib import load
# 加载模型
model=load('random_forest_model.joblib')
# 使用模型进行预测
predictions=model.predict(x)
print("predictions:",predictions.shape)
print("predictions:",predictions)

​​

助力快速掌握数据集的信息和使用方式。

数据可以如此美好!

相关推荐
明月照山海-10 分钟前
机器学习周报十
深度学习·机器学习·cnn
@Wufan11 分钟前
【机器学习】10 Directed graphical models (Bayes nets)
人工智能·机器学习
我找到地球的支点啦11 分钟前
Matlab系列(005) 一 归一化
人工智能·机器学习·matlab·信息与通信
ygy.白茶14 分钟前
线性回归入门级
人工智能·python·机器学习
@Wufan15 分钟前
【机器学习】9 Generalized linear models and the exponential family
人工智能·机器学习
德先生&赛先生19 分钟前
LeetCode-542. 01 矩阵
算法·leetcode·矩阵
HAH-HAH23 分钟前
【洛谷】P2197【模板】Nim 游戏
算法·游戏
遥感-GIS35 分钟前
遥感时序分析的基石:深度剖析Harmonized Landsat Sentinel-2 (HLS) 数据集的诞生、原理、特点与应用
机器学习·时序分析·hls·数据融合·landsat·sentinel-2
lichkingyang41 分钟前
最近遇到的几个JVM问题
java·jvm·算法
刘同学Python学习日记1 小时前
Python 办公自动化实战:Excel 批量处理 + 自动发邮件
python