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)

​​

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

数据可以如此美好!

相关推荐
万里侯22 分钟前
日志聚类之后别把 noise 扔掉:降噪应该改变视图,不抹掉证据
人工智能·微服务·ai·容器·k8s
澹锦汐25 分钟前
纯前端秋日银杏与枫叶落叶色板智能聚类器:基于 K-Means 色彩量化与直方图自动配方提取
前端·人工智能·ai·语言模型·vue·react·k-means
qq_158895411111 小时前
Suno-API 是什么?官方 V6 模型与 Python / TypeScript 接入指南
python·ai音乐·suno api
电科_银尘7 小时前
【大模型算法与工程 15】手写Self-Attention:Q、K、V与缩放点积
算法
7177778 小时前
国内 AI 研发效能工具怎么选:2026 年基于公开信息的选型框架与 Gitee 实践
人工智能·gitee
Csvn8 小时前
换供应商要改一遍代码?把模型接入收进一层网关(C04)
人工智能·aigc·agent
孟健9 小时前
开源AutoClip切直播:1小时48分出19段,整月API只花0.08元
人工智能·开源·aigc
翰墨之道9 小时前
AI日报:豆包工作ARR超20亿,GPT-6.2跑分与实测割裂
人工智能·gpt·数据挖掘
Maynor9969 小时前
Trymodel 使用介绍:一个平台同时用 Claude、GPT、Gemini 和 Grok
人工智能·gpt·ai·程序员·教程·claude·语音
郝学胜-神的一滴10 小时前
Effective STL 条款03:容器中的对象复制要廉价且正确
开发语言·数据结构·c++·算法·rpc·stl