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

相关推荐
小陈phd1 小时前
多模态大模型学习笔记(七)——多模态数据的表征与对齐
人工智能·算法·机器学习
nimadan122 小时前
**AI漫剧软件2025推荐,解锁高性价比创意制作新体验**
人工智能·python
Ro Jace3 小时前
分岔机制学习
人工智能·学习·机器学习
yunhuibin4 小时前
GoogLeNet学习
人工智能·python·深度学习·神经网络·学习
易辰君5 小时前
【Python爬虫实战】正则:中文匹配与贪婪非贪婪模式详解
开发语言·爬虫·python
秀儿还能再秀5 小时前
正则表达式核心语法 + Python的 re 库中常用方法
python·正则表达式
xcLeigh5 小时前
Python入门:Python3 正则表达式全面学习教程
python·学习·正则表达式·教程·python3
金融小师妹6 小时前
3月美联储货币政策决策的动态博弈——基于就业市场数据与通胀预测的AI模型分析
大数据·人工智能·深度学习·机器学习
多恩Stone6 小时前
【C++ debug】在 VS Code 中无 Attach 调试 Python 调用的 C++ 扩展
开发语言·c++·python