Skip to content

Commit

Permalink
Fixed intercept adjustment by prior probability in logistic regression.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasnykodym committed Jan 12, 2015
1 parent 7b346d7 commit cdd8a6b
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/main/java/hex/glm/GLM2.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void setTweediePower(double pwr){
@API(help="disable line search in all cases.",filter=Default.class, importance = ParamImportance.EXPERT, hide = true)
protected boolean disable_line_search = false; // -1 is magic value for default value which is mean(y) computed on the current dataset

private double _iceptAdjust; // adjustment due to the prior
private double _iceptAdjust = 0; // adjustment due to the prior

@API(help = "validation folds", filter = Default.class, lmin=0, lmax=100, json=true, importance = ParamImportance.CRITICAL)
protected int n_folds;
Expand Down Expand Up @@ -765,6 +765,8 @@ private String LogInfo(String msg){
int intercept = (this.intercept ?1:0);
double [] fullBeta = (_activeCols == null || newBeta == null)?newBeta:expandVec(newBeta,_activeCols);
if(val != null) val.null_deviance = _nullDeviance;
if(this.intercept)
fullBeta[fullBeta.length-1] += _iceptAdjust;
if(_noffsets > 0){
fullBeta = Arrays.copyOf(fullBeta,fullBeta.length + _noffsets);
if(this.intercept)
Expand Down Expand Up @@ -1164,14 +1166,7 @@ public void callback(final YMUTask ymut) {
_ymu = ymut.ymu();
_nobs = ymut.nobs();
if(_glm.family == Family.binomial && prior != -1 && prior != _ymu && !Double.isNaN(prior)) {
double ratio = prior / _ymu;
double pi0 = 1, pi1 = 1;
if (ratio > 1) {
pi1 = 1.0 / ratio;
} else if (ratio < 1) {
pi0 = ratio;
}
_iceptAdjust = Math.log(pi0 / pi1);
_iceptAdjust = -Math.log(_ymu * (1-prior)/(prior * (1-_ymu)));
} else prior = _ymu;
H2OCountedCompleter cmp = (H2OCountedCompleter)getCompleter();
cmp.addToPendingCount(1);
Expand Down

0 comments on commit cdd8a6b

Please sign in to comment.