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 分钟前
Conv+BN+Add+ReLU 融合机制简介
算法·自动驾驶
冬奇Lab3 分钟前
Agent 系列(9):多 Agent 架构设计模式——Supervisor 与 Pipeline
人工智能·源码·agent
冬奇Lab12 分钟前
每日一个开源项目(第118篇):SkillOpt - 像训练神经网络一样优化 LLM Agent 的技能
人工智能·开源·agent
yuanyuan2o212 分钟前
模型预训练:Hugging Face Transformers 基础
算法·ai·语言模型·自然语言处理·nlp·深度优先
杨充20 分钟前
1.3 浮点型数据设计灵魂
开发语言·python·算法
chengzi_beibei30 分钟前
浏览器自动化的下一层:为什么 CloakBrowser 把指纹问题推到了源码层?
人工智能
哥布林学者40 分钟前
深度学习进阶(二十六)现代 LLM 的核心架构设计其一:RMSNorm
机器学习·ai
甲维斯41 分钟前
免费的Qwen3.7max终于来了!
人工智能
妄想出头的工业炼药师1 小时前
GS slam mono
算法·开源