Skip to content

REF/SUMM: numpy lstsq changes default rcond in 1.14 #3994

Open

Description

@josef-pkt

https://github.com/numpy/numpy/pull/9582/files

independently of whether the change is better than the current default:

  • we might have more discrepancies in rcond/threshold across linalg function, ie. algorithm option
    (main current candidate switching linalg method in GLM.fit IRLS)
  • It will change results compared to our current behavior. But most likely we don't have unit tests where the change in rcond affects the results.
    e.g. Performance: Logit and GLM, and sklearn, IRLS slow with highly collinear exog #3990 sklearn classification examples are highly collinear, which seems to adversely affect GLM IRLS
  • results will depend on numpy version in highly collinear cases.

However, the current rcond independent of nobs is also fragile #2628
old issue for differences in threshold: #1662 (but mainly difference svd(x) versus svd(x.T x)

issue trigered by
scipy/scipy#7995 (comment)

ilayn: "These bounds are kind of standard. (well standard in the sense "that's what matlab does"). NumPy also picked these up for matrix_rank tolerance which should be inline with null basis column number. You can see more about it here https://www.ma.utexas.edu/documentation/lapack/node92.html
"
josef-pktd"
The lapack links says "p(m , n) is a modestly growing function of m and n"
My question is whether linear growth in m is not too much (e.g. sqrt(m) or log(M)?). statsmodels has some issues that constant in m (rcond independent of m) is too small.
"

TODO:

  • check consistency across fit methods and matrix_rank
  • check what p(m, n) (LAPACK) or in our case rcond(nobs) would look good in our applications. E.g. If something like law of large numbers in error accumulation holds, then it would be sqrt(nobs)
    good example to start might be the overparameterized categorical exog in REF: pinv threshold, linear regression for almost singular #2628
  • check whether we should stick with numpy default or override and try to have our own consistent rcond function

Activity

  1. changed the title [-]REF: numpy lstsq changes default rcond in 1.14[/-] [+]REF/SUMM: numpy lstsq changes default rcond in 1.14[/+] on Oct 7, 2017
  2. josef-pkt commented on Oct 7, 2017

    @josef-pkt
    MemberAuthor

    Other possibilities to make this less relevant:

    • speed up merging of penalization, i.e. use small Ridge penalty instead of spectral cutoff.
    • multicollinearity tools (another PR waiting for merge)
    • summary(): more information across models (instead of just linear_models like OLS, WLS)
      including information about rank(cov_params) although that wouldn't be informative if rank of cov_params is full because of a Ridge penalization, even if data is rank deficient.
  3. josef-pkt commented on Oct 10, 2017

    @josef-pkt
    MemberAuthor

    Another problem with rcond, this time in matrix_rank

    example: is random generated (no seed defined), simple linear model
    estimated with method QR (via wls_method argument in GLM Gaussian fit_irls, changes for #4001)

    k_exog is 4, two are constant
    pinv regularized with rank of cov_params = 3 (one missing because of collinearity)
    QR does not regularize, two bse are huge

    However, matrix_rank only looks at the largest eigen/singular value, and identifies rank as 1, i.e. 3 missing. (i.e. the rcond/singular condition was changed a several numpy versions ago, and doesn't produce meaningful results in this case. Note, results are not very reliable anyway, but QR shows the two unidentified parameters

    res3 below is estimated with wls method QR

    >>> res3.cov_params()
    array([[  3.14494568e+14,   1.53423174e-02,  -1.57247284e+14,
             -2.85395519e-03],
           [  1.71383240e-02,   1.99950023e-02,  -9.38240074e-03,
             -2.06607428e-03],
           [ -1.57247284e+14,  -8.48439742e-03,   7.86236421e+13,
              1.27716213e-03],
           [ -2.46072389e-03,  -2.06607428e-03,   1.08054648e-03,
              2.45563901e-02]])
    
    >>> np.linalg.matrix_rank(res3.cov_params())
    1
    >>> np.linalg.eigvals(res3.cov_params())
    array([  3.93118210e+14,   1.56250000e-02,   1.91983227e-02,
             2.53530697e-02])
    
    >>> res3.params
    array([  8.94161222e+14,   1.00277574e+00,  -4.47080611e+14,
             9.32631987e-01])
    
    >>> res3.bse
    array([  1.77339947e+07,   1.41403686e-01,   8.86699735e+06,
             1.56704786e-01])
    
  4. josef-pkt commented on Jan 26, 2018

    @josef-pkt
    MemberAuthor

    we get future warnings from numpy now

    e.g.
    https://ci.appveyor.com/project/josef-pkt/statsmodels/build/1.0.2827/job/6vokw8k0d0n3x897

    statsmodels/base/tests/test_data.py::TestHasConstantGLM::()::test_hasconst
      C:\projects\statsmodels\statsmodels\regression\_tools.py:92: FutureWarning: `rcond` parameter will change to the default of machine precision times ``max(M, N)`` where M and N are the input matrix dimensions.
      To use the future default and silence this warning we advise to pass `rcond=None`, to keep using the old, explicitly pass `rcond=-1`.
        params, _, _, _ = np.linalg.lstsq(self.wexog, self.wendog)
    
  5. josef-pkt commented on Mar 22, 2018

    @josef-pkt
    MemberAuthor

    #4384 made changes to keep old behavior for lstsq

    but what rcond we want to use is still open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions