【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)

相关推荐
春日见12 分钟前
自动驾驶规划控制决策知识点扫盲
linux·运维·服务器·人工智能·机器学习·自动驾驶
人工智能AI技术19 分钟前
【Agent从入门到实践】43 接口封装:将Agent封装为API服务,供其他系统调用
人工智能·python
hjs_deeplearning21 分钟前
文献阅读篇#14:自动驾驶中的基础模型:场景生成与场景分析综述(5)
人工智能·机器学习·自动驾驶
Darkershadow1 小时前
蓝牙学习之Time Set
python·学习·蓝牙·ble·mesh
m0_736919102 小时前
超越Python:下一步该学什么编程语言?
jvm·数据库·python
学习中的DGR2 小时前
[极客大挑战 2019]Http 1 新手解题过程
网络·python·网络协议·安全·http
布茹 ei ai2 小时前
Python屏幕监视器 - 自动检测屏幕变化并点击
开发语言·python
天天睡大觉2 小时前
Python学习12
网络·python·学习
程序员杰哥3 小时前
性能测试详解
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·性能测试
人工智能AI技术3 小时前
【Agent从入门到实践】42实战:用Docker打包Agent,实现一键部署
人工智能·python