周志华《机器学习》课后习题解答系列(五):Ch4 - 决策树

本章所涉及编程练习采用Python-sklearn的方式,环境搭建可参考 数据挖掘入门:Python开发环境搭建(eclipse-pydev模式).

查看相关答案和源代码,欢迎访问我的Github:PY131/Machine-Learning_ZhouZhihua.

本章概要

本章讲述决策树(decision tree),相关内容包括:

  • 决策树生成(construction)

子决策(sub-decision)、递归生成算法(basic algorithm)、最优划分属性、纯度(purity)、信息熵(information entropy)、信息增益(information gain)、ID3 、增益率(gain ratio)、C4.5 、基尼指数(gini index)、CART

  • 剪枝(pruning)

过拟合、泛化能力、预剪枝(prepruning)(自上而下)、决策树桩(decision stump)、欠拟合、后剪枝(postpruning)(自下而上)、完全树。

  • 连续属性、缺失值(continuous variables, missing values)

连续属性离散化、二分法(bi-partition)、值缺失时属性划分、缺值样本划分、权重、加权信息增益;

  • 多变量决策树(multivariate decision tree)

斜划分、斜决策树(oblique decision tree)、非叶节点-线性分类器;

此外还提及了C4.5Rule、OC1、感知机树等拓展方法,以及增量学习算法ID4、ID5R、ITI等;

决策树的优劣总结

根据sklearn官网 - 1.10.Decision Trees总结如下:

  1. 优势(Advantages):

    • 易理解,解释性好,易可视化&#x
  • 13
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
周志华是一位著名的机器学习专家,他在《机器学习》一书中详细介绍了决策树算法。下面是决策树算法的伪代码: 1. 定义决策树节点类: class DecisionTreeNode: def __init__(self): self.feature = None # 当前节点选择的特征 self.threshold = None # 特征的阈值 self.label = None # 叶子节点的类别标签 self.left_child = None # 左子树 self.right_child = None # 右子树 2. 定义决策树构建函数: def build_decision_tree(data, labels): # 创建新节点 node = DecisionTreeNode() # 如果所有样本属于同一类别,则将当前节点标记为叶子节点,并返回 if all_same_class(labels): node.label = labels return node # 如果没有特征可用,则将当前节点标记为叶子节点,并返回 if no_more_features(): node.label = majority_class(labels) return node # 选择最优特征和阈值 best_feature, best_threshold = choose_best_feature(data, labels) node.feature = best_feature node.threshold = best_threshold # 根据最优特征和阈值划分数据集 left_data, left_labels, right_data, right_labels = split_data(data, labels, best_feature, best_threshold) # 递归构建左子树和右子树 node.left_child = build_decision_tree(left_data, left_labels) node.right_child = build_decision_tree(right_data, right_labels) return node 3. 定义决策树预测函数: def predict(node, sample): if node.label is not None: return node.label if sample[node.feature] <= node.threshold: return predict(node.left_child, sample) else: return predict(node.right_child, sample) 以上是决策树算法的伪代码,其中包括了决策树节点类的定义、决策树构建函数和决策树预测函数。通过递归地选择最优特征和阈值来构建决策树,并使用构建好的决策树进行样本的预测。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值