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)

​​

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

数据可以如此美好!

相关推荐
极小狐1 小时前
比 Cursor 更丝滑的 AI DevOps 编程智能体 - CodeRider-Kilo 正式发布!
运维·人工智能·devops
草莓火锅1 小时前
用c++使输入的数字各个位上数字反转得到一个新数
开发语言·c++·算法
散峰而望1 小时前
C/C++输入输出初级(一) (算法竞赛)
c语言·开发语言·c++·算法·github
Kuo-Teng2 小时前
LeetCode 160: Intersection of Two Linked Lists
java·算法·leetcode·职场和发展
半臻(火白)2 小时前
Prompt-R1:重新定义AI交互的「精准沟通」范式
人工智能
fie88892 小时前
基于MATLAB的狼群算法实现
开发语言·算法·matlab
菠菠萝宝2 小时前
【AI应用探索】-10- Cursor实战:小程序&APP - 下
人工智能·小程序·kotlin·notepad++·ai编程·cursor
dreams_dream2 小时前
Flask
后端·python·flask
偷偷的卷2 小时前
【算法笔记 11】贪心策略六
笔记·算法
连线Insight2 小时前
架构调整后,蚂蚁继续死磕医疗健康“硬骨头”
人工智能