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)

​​

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

数据可以如此美好!

相关推荐
TG:@yunlaoda360 云老大13 分钟前
谷歌云AI 时代的算力革命:CPU、GPU 到 TPU 的架构与定位解析
人工智能·架构·googlecloud
AKAMAI15 分钟前
加速采用安全的企业级 Kubernetes 环境
人工智能·云计算
Aspect of twilight26 分钟前
深度学习各种优化器详解
人工智能·深度学习
徽44032 分钟前
农田植被目标检测数据标注与模型训练总结2
人工智能·目标检测·目标跟踪
月明长歌32 分钟前
【码道初阶】一道经典简单题:多数元素(LeetCode 169)|Boyer-Moore 投票算法详解
算法·leetcode·职场和发展
wadesir37 分钟前
C语言模块化设计入门指南(从零开始构建清晰可维护的C程序)
c语言·开发语言·算法
Elastic 中国社区官方博客40 分钟前
Elasticsearch 中使用 NVIDIA cuVS 实现最高快 12 倍的向量索引速度:GPU 加速第 2 章
大数据·人工智能·elasticsearch·搜索引擎·ai·全文检索·数据库架构
t1987512841 分钟前
MATLAB水声信道仿真程序
开发语言·算法·matlab
white-persist1 小时前
VSCode 快捷键大全:从设计理念到场景化高效运用(详细解析)(文章末尾有vim快捷键大全)
linux·ide·vscode·python·编辑器·系统安全·vim
liliangcsdn1 小时前
python threading异步并发调用示例
python