决策树与森林:构建、优化与交叉验证
1. 决策树的构建
在构建决策树时,我们的目标是从样本和初始特征集合中生成一棵树。具体步骤如下:
1. 寻找最具信息性的特征 :对于给定的样本,找出能带来最大熵增益的特征。
2. 创建树桩(Stump) :为该特征创建一个树桩,树桩包含特征名称、默认值和子树分支。
3. 递归构建 :重复上述步骤,直到没有可用特征或数据量过少。
以下是构建决策树的代码:
let mostFrequentBy f sample =
sample
|> Seq.map f
|> Seq.countBy id
|> Seq.maxBy snd
|> fst
let rec growTree sample label features =
if (Map.isEmpty features)
// we have no feature left to split on:
// our prediction is the most frequent
// label in the dataset
then sample |> mostFrequentBy label |> Answer
else
// from the named features we have available,
// identify the
超级会员免费看
订阅专栏 解锁全文
6286

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



