All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hex.genmodel.algos.tree.CalibrationMojoHelper Maven / Gradle / Ivy

There is a newer version: 3.46.0.6
Show newest version
package hex.genmodel.algos.tree;

import hex.genmodel.algos.isotonic.IsotonicCalibrator;

import static hex.genmodel.GenModel.GLM_logitInv;

public class CalibrationMojoHelper {

    public interface MojoModelWithCalibration {
        double[] getCalibGlmBeta();
        IsotonicCalibrator getIsotonicCalibrator();
    }

    public static boolean calibrateClassProbabilities(MojoModelWithCalibration model, double[] preds) {
        if (model.getCalibGlmBeta() != null) {
            double p = GLM_logitInv((preds[1] * model.getCalibGlmBeta()[0]) + model.getCalibGlmBeta()[1]);
            preds[1] = 1 - p;
            preds[2] = p;
            return true;
        } else if (model.getIsotonicCalibrator() != null) {
            double p = model.getIsotonicCalibrator().calibrateP1(preds[2]);
            preds[1] = 1 - p;
            preds[2] = p;
            return true;
        }
        return false;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy