You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
automatic transformation, scaling or scaling checks or preprocessing #1131
I ran into an example with some badly scaled variables (Cameron Trivedi count data similar to randhi).
It took me a while to figure out that the bad scaling was the reason for numerical problems:
very large condition number, almost singular
fmin_bfgs goes out of range (huge numbers)
fmin ("nm") was still ok, but not very precise
Stata doesn't seem to have a problem with the original unscaled data. As far as I know, Stata treats the constant differently, but I haven't read that they also rescale.
I haven't tried if demeaning would be enough in this case.
In my case the user wouldn't see part of the rescaling gmm instruments or first stage of IV2SLS.
For other cases, we would have to transform the parameters to adjust for any scaling.
At least a warning would be useful to point out the problem to users.
An idea for stronger numerical stabilisation: use pinv like transformation (analog to linear model)
If the underlying exog dependent part is linear x dot beta, then we can transform the exog before fitting and retransform after fitting.
Instead of just rescaling exog, we can orthogonalize exog, which is just a linear, possibly rank reduced, transformation of the data and the linear parameters, beta.
This would correspond to using the analog of a PCA (SVD) regression internally during the optimization, but we report the results in the original exog space.
From my previous experiments, OLS with pinv produces numerically unstable results only in very extreme cases of bad scaling or almost perfect multicollinearity. (one NIST case)
Non-linear optimization like in the discrete models are numerically much less robust.
related for Hessian: #953 linalg.inv in Newton fails relatively easily
Another example using squares
restricted least squares rls has an example with x and x**2 in the exog. However, x is large. Without rescaling x, rank(exog) is full rank, the estimated cov_params has reduced rank.
Looks like pinv truncation might not be kicking in yet, but inverting for cov_params produces a eigenvalue of around 1e-18, and np.linalg.matrix_rank(res.cov_params()) shows reduce rank
(The actual example is not clear yet, because I only use the restricted model where we have on intentional singularity, perfect correlation among exogs that is removed by one linear restriction.)
changed the title [-]automatic scaling or scaling checks or preprocessing[/-][+]automatic transformation, scaling or scaling checks or preprocessing[/+]on May 27, 2014
partial transformation: make it possible that we only standardize or transform some of the exog.
example usecase
we have 5 parameters that we are interested in and don't want to penalize, we have another set of potential explanatory variables where we don't care about the parameters.
-> Transform and penalize only the extra variables ("confounders")
another reference:
Beta Regression article (*) has an online appendix that mentions several optimization problems, one of them is that larger values of exog cause problems with log link (exp mean function).
Sounds like same problem that I ran into with Poisson and Negative Binomial.
There was also a recent StackOverflow question where a logistic regression was failing because of badly scaled variables, which makes sense. Would be nice to have a cookbook notebook using the current scaling using StandardizeTransform to point to.
The stackoverflow question triggered that I look into this again.
But besides scaling, we also need better default start_params.
GLM might have better starting values in cases like this.
BetaRegression also can run into optimization problems if the starting values are not good.
Activity
josef-pkt commentedon May 16, 2014
Another example using squares
restricted least squares rls has an example with x and x**2 in the exog. However, x is large. Without rescaling x, rank(exog) is full rank, the estimated cov_params has reduced rank.
Looks like pinv truncation might not be kicking in yet, but inverting for cov_params produces a eigenvalue of around 1e-18, and
np.linalg.matrix_rank(res.cov_params())shows reduce rank(The actual example is not clear yet, because I only use the restricted model where we have on intentional singularity, perfect correlation among exogs that is removed by one linear restriction.)
josef-pkt commentedon May 27, 2014
see comment about behavior of
fmin_cg#1641 (comment)[-]automatic scaling or scaling checks or preprocessing[/-][+]automatic transformation, scaling or scaling checks or preprocessing[/+]josef-pkt commentedon Jun 20, 2014
partial transformation: make it possible that we only standardize or transform some of the exog.
example usecase
we have 5 parameters that we are interested in and don't want to penalize, we have another set of potential explanatory variables where we don't care about the parameters.
-> Transform and penalize only the extra variables ("confounders")
josef-pkt commentedon Dec 14, 2014
another reference:
Beta Regression article (*) has an online appendix that mentions several optimization problems, one of them is that larger values of exog cause problems with log link (exp mean function).
Sounds like same problem that I ran into with Poisson and Negative Binomial.
(*) #2030 (comment) "A Better Lemon Squeezer"
jseabold commentedon Dec 15, 2014
There was also a recent StackOverflow question where a logistic regression was failing because of badly scaled variables, which makes sense. Would be nice to have a cookbook notebook using the current scaling using
StandardizeTransformto point to.josef-pkt commentedon Dec 15, 2014
The stackoverflow question triggered that I look into this again.
But besides scaling, we also need better default start_params.
GLM might have better starting values in cases like this.
BetaRegression also can run into optimization problems if the starting values are not good.
josef-pkt commentedon Sep 25, 2015
Another case, the first time I see it explicit in Stata
Stata
slogitstandardizes exog for the optimization with optionnonormalizeto turn it off.