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)

​​

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

数据可以如此美好!

相关推荐
超级架构师2 分钟前
让 Fortran 模型自己调用 Agent:原生 Fortran 2008 实现深度剖析
人工智能·python·架构·机器人·开源·fortran
小蒜学长7 分钟前
基于Django+Vue喵汪联盟宠物领养系统的设计与实现(代码+数据库+LW)
后端·python·django·宠物领养系统·流程规范化
fly-iot16 分钟前
【FDE知识库】(1):AI 编程时代开发语言选型分析,云使用go,企业用java,算法python,底层c
开发语言·人工智能·golang
云边有个稻草人16 分钟前
Prometheus Pushgateway教程:离线任务指标上报、Shell与Python示例、远程访问
开发语言·python·prometheus
郝学胜-神的一滴20 分钟前
游戏设计:原型与开发 17:数字化系统里的思维体操
人工智能·游戏·游戏程序·游戏策划·游戏设计
fanruitian30 分钟前
pycharm 使用anaconda
ide·python·pycharm
腾讯云大数据31 分钟前
腾讯云发布一站式多模态数据处理与模型训推方案,助力Physical AI释放生产力
大数据·人工智能·云计算·腾讯云
Dwzun32 分钟前
基于SpringBoot3+Vue3的油莎豆种植管理系统
java·前端·vue.js·spring boot·后端·python·计算机网络
GitCode官方1 小时前
从大语言模型到具身智能:百度百舸 LoongForge 入驻 AtomGit
人工智能·react native·百度·harmonyos·atomgit
Easy_API9 小时前
2.8万亿参数,编程反超GPT-6 Astra:Kimi K3.1 Pro把开源模型推到了哪一步
大数据·人工智能·gpt·深度学习