Hi Paul,

PLSRegression in sklearn uses an iterative method to estimate the eigen
vectors and values (I think it is the power method) , which mostly varies
depending  on the underlying library that you use,
I would suggest to use SVD instead if you want to get stable results and
your dataset is small

I have wrote also wrote a Kernal PLS which you can find here
https://gist.github.com/aeweiwi/7788156


Cheers,


On Tue, Feb 14, 2017 at 11:54 AM, Paul Anton Letnes <[email protected]> wrote:

> Hi!
>
> Versions:
> sklearn 0.18.1
> numpy 1.11.3
> Anaconda python 3.5 on ubuntu 16.04
>
> What range is the cross_val_score supposed to be in? I was under the
> impression from the documentation, although I cannot find it stated
> explicitly anywhere, that it should be a number in the range [0, 1].
> However, it appears that one can get large negative values; see the ipython
> session below.
>
> Cheers
> Paul
>
> In [2]: import numpy as np
>
> In [3]: y = np.random.random((10, 3))
>
> In [4]: x = np.random.random((10, 17))
>
> In [5]: from sklearn.cross_decomposition import PLSRegression
>
> In [6]: pls = PLSRegression(n_components=3)
>
> In [7]: from sklearn.cross_validation import cross_val_score
>
> In [8]: from sklearn.model_selection import cross_val_score
>
> In [9]: cross_val_score(pls, x, y)
> Out[9]: array([-32.52217837,  -4.17228083,  -5.88632365])
>
>
> PS:
> This happens even if I cheat by setting y to the predicted value, and
> cross validate on that.
>
> In [29]: y = x @ pls.coef_
>
> In [30]: cross_val_score(pls, x, y)
> /home/paul/anaconda3/envs/wp3-paper/lib/python3.5/site-
> packages/sklearn/cross_decomposition/pls_.py:293: UserWarning: Y residual
> constant at iteration 5
>   warnings.warn('Y residual constant at iteration %s' % k)
> /home/paul/anaconda3/envs/wp3-paper/lib/python3.5/site-
> packages/sklearn/cross_decomposition/pls_.py:293: UserWarning: Y residual
> constant at iteration 6
>   warnings.warn('Y residual constant at iteration %s' % k)
> /home/paul/anaconda3/envs/wp3-paper/lib/python3.5/site-
> packages/sklearn/cross_decomposition/pls_.py:293: UserWarning: Y residual
> constant at iteration 6
>   warnings.warn('Y residual constant at iteration %s' % k)
> Out[30]: array([-35.01267353,  -4.94806383,  -5.9619526 ])
>
> In [34]: np.max(np.abs(y - x @ pls.coef_))
> Out[34]: 0.0
>
>
>
> _______________________________________________
> scikit-learn mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/scikit-learn
>
>
_______________________________________________
scikit-learn mailing list
[email protected]
https://mail.python.org/mailman/listinfo/scikit-learn

Reply via email to