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)

​​

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

数据可以如此美好!

相关推荐
智驱力人工智能43 分钟前
智慧物流中心为何需要包装缺陷检测 商品包装检测 包装标签合规检测 物流包装AI视觉检测系统 电商包装自动化检测 快递封箱完整性AI识别
人工智能·opencv·目标检测·计算机视觉·视觉检测·边缘计算
absunique44 分钟前
算法设计模式看编程思维的抽象能力的技术6
算法·设计模式
Elastic 中国社区官方博客1 小时前
SearchClaw:将 Elasticsearch 通过可组合技能引入 OpenClaw
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
acanab2 小时前
vscode对isaac lab开发时包不能正常导入的问题
vscode·python
DeepModel2 小时前
【概率分布】Beta分布详解
算法·概率论
weixin_505154462 小时前
博维数孪携手微软,打造智能电网数字化手册新标杆
大数据·人工智能·智慧城市·数字孪生·产品交互展示
我命由我123452 小时前
React - 验证 Diffing 算法、key 的作用
javascript·算法·react.js·前端框架·html·html5·js
Daydream.V3 小时前
Opencv——图片处理(二)
人工智能·opencv·计算机视觉
Jasmine8393 小时前
OpenClaw部署太难? Codex全流程零编码实现浏览器UI自动化
人工智能·测试工具·ui
AI2512244 小时前
AI视频生成器技术评测:运动质量与稳定性分析
人工智能·microsoft·音视频