机器学习中的分类不确定性估计、模型选择与无监督学习
1. 分类中的概率预测
在分类任务中, predict_proba 方法输出每个类别的概率,对于二分类问题,其输出形状通常为 (n_samples, 2) 。以下是一个示例代码:
import numpy as np
import mglearn
import matplotlib.pyplot as plt
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.model_selection import train_test_split
# 假设 X 和 y 已经定义
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
gbrt = GradientBoostingClassifier().fit(X_train, y_train)
fig, axes = plt.subplots(1, 2, figsize=(13, 5))
mglearn.tools.plot_2d_separator(gbrt, X, ax=axes[0], alpha=.4, fill=True, cm=mglearn.cm2)
scores_image = mglearn.tools.plot_2d_scores(gbrt, X, ax=axes[1], alpha=.4, cm='bwr')
for ax in axes:
# plot training a
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



