使用Adaboost实现make_circles数据集的分类(sklearn)

本文介绍了如何利用Adaboost算法和决策树在make_circles数据集上进行分类。Adaboost通过迭代增强弱分类器,每次迭代侧重于纠正前一轮分类错误的样本,从而逐步提升整体分类效果。最终,多个决策树的集成展现出更强的分类能力。
摘要由CSDN通过智能技术生成

使用Adaboost进行分类的基本思想是基于弱分类器的Boosting, 在每次迭代的样本中,增加上一次迭代中分类错误的样本的权重。
在这里插入图片描述
下面是基本的使用Adaboost和决策树(层数为1)对make_circle进行分类。

# coding: utf-8
# Referenzen
# - https://scikit-learn.org/stable/modules/ensemble.html#adaboost
# - https://xavierbourretsicotte.github.io/AdaBoost.html
# - [1] T. Hastie, R. Tibshirani and J. Friedman, "Elements of Statistical Learning Ed. 2", Springer, 2009.
from sklearn.tree import DecisionTreeClassifier
import numpy as np
from matplotlib.colors import ListedColormap
from sklearn import datasets
from sklearn.ensemble import AdaBoostClassifier
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
import utils


def plot_dataset(X_train: np.ndarray, X_test: np.ndarray, y_train: np.ndarray, y_test: np.ndarray) -> None:
    """Creates as scatterplot for the given dataset. The points for the first class are blue and the points for the
     second class are red. Training points are displayed as dots and testpoints are described by an X."""
    plt.figure(figsize=(6,5))
    plt.scatter(*X_train.T, c=y_train, cmap=ListedColormap(["#FF0000", "#0000FF"]),label="Training Points", marker="o")
    plt.scatter(*X_test.T, c=y_test, cmap=ListedColormap(["#FF0000", "#0000FF"]), label="Test Points", marker="x")

    plt.xlabel("$X_0$")
    plt.ylabel("$X_1$")
    plt.legend()
    plt.show()


def plot_decision_boundary_stump(stump: DecisionTreeClassifier, X: np.ndarray, y: np.ndarray, N=1000) -> None:
    """Plot the decision boundary for a tree stump and scatters plot of the training data"""
    x_min, x_max=X[:,0].min()-
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值