import mir.ndslice : sliced, iota; import numir : unsqueeze; import dtree.impurity : gini, entropy; { Classification!entropy c; auto xs = [-2.0, -1.0, 0.0, 1.0].sliced.unsqueeze!1; // for dmd ys needs to be long or size_t auto ys = [0, 0, 0, 1].sliced!long; c.fit(xs[2], xs, ys, iota(ys.length), 0, 2); assert(c.left.index == [0, 1, 2]); assert(c.right.index == [3]); assert(c.threshold == xs[2][0]); assert(c.left.prediction == [1, 0]); assert(c.right.prediction == [0, 1]); assert(c.left.impurity == 0.0); assert(c.right.impurity == 0.0); } { Classification!gini c; auto xs = [-2.0, -1.0, 0.0, 1.0].sliced.unsqueeze!1; auto ys = [0, 0, 0, 1].sliced!long; c.fit(xs[2], xs, ys, iota(ys.length), 0, 2); assert(c.left.index == [0, 1, 2]); assert(c.right.index == [3]); assert(c.threshold == xs[2][0]); assert(c.left.prediction == [1, 0]); assert(c.right.prediction == [0, 1]); assert(c.left.impurity == 0.0); assert(c.right.impurity == 0.0); }
classification desicion implementation used at Node