假设我有以下的树形结构:功能,构建二元决策树
type Tree =
| Branch of (string*string) * (Tree*Tree)
| Leaf of float
例如,它可能是这个样子:
Branch (("X1",">4.5"), (Branch (("X2",">4.5"), (Leaf 3.4, Leaf 5.5)), Branch (("X3",">4.5"), (Leaf 6.5, Leaf 4.5))))
这将是一个功能的主要部分创建一个这样的树(从数据,随机或其他)? 我知道我的问题与how to make a tree from a given data with F#类似,但是我正在将最难的时间翻译到我的树上。
编辑:我试图建立一个决策树,我开始与树here看起来像这样:
type DecisionTreeNode =
// Attribute name and value/child node list
| DecisionNode of string * (string * DecisionTreeNode) seq
// Decision and corresponding evidence
| Leaf of bool * Record seq
然而,我的是一个回归树,所以它应该有漂浮的叶子,我只想要二进制分割,所以我想我可以使用元组而不是seq作为节点。 在那棵树再次寻找后,我想知道如果我的应该是这样的:
type Tree =
| Branch of string*((string*Tree)*(string*Tree))
| Leaf of float
你被困在什么特定部分?所以我不在这里写所有我的代码问题 –
我有点澄清了这个问题。 – dood