brendanhasz / probflow

A Python package for building Bayesian models with TensorFlow or PyTorch
http://probflow.readthedocs.io
MIT License
171 stars 17 forks source link

Inverted Logistic Regression coefficients #13

Closed arainboldt closed 4 years ago

arainboldt commented 5 years ago

Hi,

I'm comparing the Logistic Regression application with TFP.glm and PYMC. I'm consistently getting inverted signs on the coefficients for the regressors from probflow vs TFP.glm and PYMC. Below is the summary from the pymc model with the appended coefficients from tfp and probflow

`

coeff pymc_mean pf_mean tfp_glm_mean
coeffs[0] 1.073 -0.884923 0.245316
coeffs[1] -1.394 0.593529 -0.760361
coeffs[2] 0.775 -0.524494 0.000000
coeffs[3] 0.654 -0.413936 -0.112381
coeffs[4] 1.052 -0.811504 0.179820
coeffs[5] -0.973 0.203751 -0.368867
coeffs[6] -0.101 -0.760126 0.487476
coeffs[7] -0.389 0.094798 0.000000
coeffs[8] -1.542 1.092922 -1.059176
coeffs[9] -2.604 1.211063 -1.140007
coeffs[10] -1.814 0.985445 -0.953259
coeffs[11] -1.752 1.183555 -1.161227
coeffs[12] -0.954 0.547342 -0.444315
coeffs[13] -1.981 0.841193 -0.525483
coeffs[14] -26.866 0.654583 0.000000
coeffs[15] -26.745 0.328704 0.000000
coeffs[16] -1.228 0.516039 -0.276005
coeffs[17] -1.282 0.318989 0.000000
coeffs[18] 26.991 -0.357874 0.000000
coeffs[19] -1.081 0.551722 -0.392427

`

You'll see that although the tfp.glm differs in magnitude from pymc, generally the signs are the same, while the probflow coefficients generally have the opposite sign. This will create issues when trying to interpret probflow models. Any ideas what might be the cause of this?

brendanhasz commented 5 years ago

Hi!

You're using pf.LogisticRegression, right? Looks like I used the 2nd class as the pivot for the additive logistic transform instead of the 1st class, which was dumb, because like you found out, then all the coefficients are backwards haha!

Fixed it in https://github.com/brendanhasz/probflow/commit/2be4ef88ad7a4002dd39807d410594a995ccd2db - the coefficients should be of the expected sign now.

Thanks for pointing out the problem and lemme know if that fixes it or not!

Brendan

arainboldt commented 5 years ago

Thanks for the quick response. Right on. I'll update and let you know!