【Python机器学习】多分类问题的不确定度

decision_function和predict_proba也适用于多分类问题。还是以鸢尾花数据集为例:

python 复制代码
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.datasets import make_circles,load_iris
import numpy as np
from sklearn.model_selection import train_test_split

iris=load_iris()
X_train,X_test,y_train,y_test=train_test_split(
    iris.data,iris.target,random_state=0
)

gbrt=GradientBoostingClassifier(learning_rate=0.01,random_state=0)
gbrt.fit(X_train,y_train)
print('决策函数结果的形状:{}'.format(gbrt.decision_function(X_test).shape))
print('决策函数结果:{}'.format(gbrt.decision_function(X_test)[:6,:]))

可以看到,对于多分类的情况, decision_function的形状为(n_samples,n_classes),每一列对应每个类别的"确定度分数",分数较高的类别可能性更大,得分较低的分类可能性小,可以找到每个数据点的最大元素,也就是预测结果:

python 复制代码
print('决策函数得分最高的分类:{}'.format(np.argmax(gbrt.decision_function(X_test),axis=1)))
print('模型预测结果:{}'.format(gbrt.predict(X_test)))

predict_proba输出的形状相同,也是(n_samples,n_classes),每个数据点的所有可能类别的概率相加为1:

python 复制代码
print('预测每个分类的概率:{}'.format(gbrt.predict_proba(X_test)[:6]))

总之,decision_function和predict_proba的形状始终相同,都是(n_samples,n_classes)

相关推荐
摆烂老大16 分钟前
论文学习 | HESS2025 | 中亚寒区季节水文预报
学习·机器学习·水文
2601_9669496523 分钟前
实时行情中的成交量 Volume 到底是什么?包含盘中撤单量吗?从交易数据语义到 QuantDash 实战解析
开发语言·人工智能·python·量化·quantdash·量化数据源
you鬰31 分钟前
datawhale--llm-algo-leetcode9️⃣ SFT Training Loop
python·datawhale
叫我:松哥38 分钟前
基于flask仿小米商城管理系统,使用flask开的一个商场网站
数据库·后端·python·flask
智购科技无人售货机工厂1 小时前
2026自动售货机防拆机物理安全设计:从安全螺丝到结构互锁的工程实践~YH
android·网络·驱动开发·python·单片机·安全·云原生
2401_868534781 小时前
校园网规划与设计
python·pygame
小猴子爱上树1 小时前
跨境电商AI批量图片翻译工具,视频字幕翻译免费试用
人工智能·python·音视频
zx_741484811 小时前
【Python入门】爬虫实战:Requests + XPath 从基础到实战
开发语言·爬虫·python
高洁011 小时前
Teacher Forcing技术解析
人工智能·python·深度学习·transformer·知识图谱
MartinYeung51 小时前
[论文分析]使大型语言模型智能体与理性和道德偏好对齐:一种监督微调方法
人工智能·机器学习·语言模型