Classification

classification desicion implementation used at Node

Members

Functions

fit
void fit(X x, Xs xs, Ys ys, I index, size_t fid, size_t nPreds)
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

left
DecisionInfo left;
right
DecisionInfo right;
Undocumented in source.
threshold
double threshold;
Undocumented in source.

Examples

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);
}

Meta