本文整理汇总了Python中sklearn.ensemble.AdaBoostClassifier.estimator_errors_方法的典型用法代码示例。如果您正苦于以下问题:Python AdaBoostClassifier.estimator_errors_方法的具体用法?Python AdaBoostClassifier.estimator_errors_怎么用?Python AdaBoostClassifier.estimator_errors_使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.ensemble.AdaBoostClassifier
的用法示例。
在下文中一共展示了AdaBoostClassifier.estimator_errors_方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_adaboost
# 需要导入模块: from sklearn.ensemble import AdaBoostClassifier [as 别名]
# 或者: from sklearn.ensemble.AdaBoostClassifier import estimator_errors_ [as 别名]
def plot_adaboost():
X, y = make_moons(noise=0.3, random_state=0)
# Create and fit an AdaBoosted decision tree
est = AdaBoostClassifier(DecisionTreeClassifier(max_depth=1),
algorithm="SAMME.R",
n_estimators=200)
sample_weight = np.empty(X.shape[0], dtype=np.float)
sample_weight[:] = 1. / X.shape[0]
est._validate_estimator()
est.estimators_ = []
est.estimator_weights_ = np.zeros(4, dtype=np.float)
est.estimator_errors_ = np.ones(4, dtype=np.float)
plot_step = 0.02
# Plot the decision boundaries
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, plot_step),
np.arange(y_min, y_max, plot_step))
fig, axes = plt.subplots(1, 4, figsize=(14, 4), sharey=True)
colors = ['#d7191c', '#fdae61', '#ffffbf', '#abd9e9', '#2c7bb6']
c = lambda a, b, c: map(lambda x: x / 254.0, [a, b, c])
colors = [c(215, 25, 28),
c(253, 174, 97),
c(255, 255, 191),
c(171, 217, 233),
c(44, 123, 182),
]
for i, ax in enumerate(axes):
sample_weight, estimator_weight, estimator_error = est._boost(i, X, y, sample_weight)
est.estimator_weights_[i] = estimator_weight
est.estimator_errors_[i] = estimator_error
sample_weight /= np.sum(sample_weight)
Z = est.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
ax.contourf(xx, yy, Z,
cmap=matplotlib.colors.ListedColormap([colors[1], colors[-2]]),
alpha=1.0)
ax.axis("tight")
# Plot the training points
ax.scatter(X[:, 0], X[:, 1],
c=np.array([colors[0], colors[-1]])[y],
s=20 + (200 * sample_weight) ** 2, cmap=plt.cm.Paired)
ax.set_xlim(x_min, x_max)
ax.set_ylim(y_min, y_max)
ax.set_xlabel('$x_0$')
if i == 0:
ax.set_ylabel('$x_1$')
plt.tight_layout()
plt.show()