Search in sources :

Example 1 with AUC2

use of hex.AUC2 in project h2o-3 by h2oai.

the class ModelMetricsBinomialV3 method fillFromImpl.

@Override
public S fillFromImpl(ModelMetricsBinomial modelMetrics) {
    super.fillFromImpl(modelMetrics);
    //    sigma = modelMetrics._sigma;
    r2 = modelMetrics.r2();
    logloss = modelMetrics._logloss;
    mean_per_class_error = modelMetrics._mean_per_class_error;
    AUC2 auc = modelMetrics._auc;
    if (null != auc) {
        AUC = auc._auc;
        Gini = auc._gini;
        // Fill TwoDimTable
        String[] thresholds = new String[auc._nBins];
        for (int i = 0; i < auc._nBins; i++) thresholds[i] = Double.toString(auc._ths[i]);
        AUC2.ThresholdCriterion[] crits = AUC2.ThresholdCriterion.VALUES;
        String[] colHeaders = new String[crits.length + 2];
        String[] colHeadersMax = new String[crits.length - 8];
        String[] types = new String[crits.length + 2];
        String[] formats = new String[crits.length + 2];
        colHeaders[0] = "Threshold";
        types[0] = "double";
        formats[0] = "%f";
        int i;
        for (i = 0; i < crits.length; i++) {
            if (colHeadersMax.length > i)
                colHeadersMax[i] = "max " + crits[i].toString();
            colHeaders[i + 1] = crits[i].toString();
            types[i + 1] = crits[i]._isInt ? "long" : "double";
            formats[i + 1] = crits[i]._isInt ? "%d" : "%f";
        }
        colHeaders[i + 1] = "idx";
        types[i + 1] = "int";
        formats[i + 1] = "%d";
        TwoDimTable thresholdsByMetrics = new TwoDimTable("Metrics for Thresholds", "Binomial metrics as a function of classification thresholds", new String[auc._nBins], colHeaders, types, formats, null);
        for (i = 0; i < auc._nBins; i++) {
            int j = 0;
            thresholdsByMetrics.set(i, j, Double.valueOf(thresholds[i]));
            for (j = 0; j < crits.length; j++) {
                // Note: casts to Object are NOT redundant
                double d = crits[j].exec(auc, i);
                thresholdsByMetrics.set(i, 1 + j, crits[j]._isInt ? (Object) ((long) d) : d);
            }
            thresholdsByMetrics.set(i, 1 + j, i);
        }
        this.thresholds_and_metric_scores = new TwoDimTableV3().fillFromImpl(thresholdsByMetrics);
        // Fill TwoDimTable
        TwoDimTable maxMetrics = new TwoDimTable("Maximum Metrics", "Maximum metrics at their respective thresholds", colHeadersMax, new String[] { "Threshold", "Value", "idx" }, new String[] { "double", "double", "long" }, new String[] { "%f", "%f", "%d" }, "Metric");
        for (i = 0; i < colHeadersMax.length; i++) {
            int idx = crits[i].max_criterion_idx(auc);
            maxMetrics.set(i, 0, idx == -1 ? Double.NaN : auc._ths[idx]);
            maxMetrics.set(i, 1, idx == -1 ? Double.NaN : crits[i].exec(auc, idx));
            maxMetrics.set(i, 2, idx);
        }
        max_criteria_and_metric_scores = new TwoDimTableV3().fillFromImpl(maxMetrics);
    }
    if (modelMetrics._gainsLift != null) {
        TwoDimTable t = modelMetrics._gainsLift.createTwoDimTable();
        if (t != null)
            this.gains_lift_table = new TwoDimTableV3().fillFromImpl(t);
    }
    return (S) this;
}
Also used : TwoDimTable(water.util.TwoDimTable) AUC2(hex.AUC2)

Aggregations

AUC2 (hex.AUC2)1 TwoDimTable (water.util.TwoDimTable)1