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
SparsePCA and MiniBatchSparsePCA will output different results on the method transform if it is applied on all the data or a subset. This issue follows from the PR #10428
On 9 January 2018 at 10:44, Jonathan Ohayon ***@***.***> wrote:
Description
SparsePCA and MiniBatchSparsePCA will output different results on the
method transform if it is applied on all the data or a subset. This issue
follows from the PR #10428
<#10428>
Steps/Code to Reproduce
import numpy as npfrom sklearn.decomposition import SparsePCA
rnd = np.random.RandomState(0)
X = 2 * rnd.uniform(size=(5, 2))
y = X[:, 0].astype(np.int)
spca = SparsePCA()
spca.fit(X,y)
res_all = spca.transform(X)
res_one = np.array([spca.transform(X[i].reshape(1, X.shape[1]))[0]
for i in range(X.shape[0])])print(res_all)print(res_one)
Expected Results
res_one = res_all
Actual Results
[[-0.48574184 -0.39159711]
[-0.3700734 -0.43009217]
[-0.43867793 -0.30229211]
[-0.60567379 -0.31223336]
[-0.26042556 -0.68760616]]
[[-1. -1.]
[-1. -1.]
[-1. -1.]
[-1. -1.]
[-1. -1.]]
Versions
Python 3.6.1 |Anaconda custom (64-bit)| (default, May 11 2017, 13:09:58)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
NumPy 1.12.1
SciPy 0.19.0
Scikit-Learn 0.19.1 ```
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#10431>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AAEz68wzXkHZu3VUmhYtT27xIhIH7wFiks5tIqhEgaJpZM4RXHap>
.
I think that maybe this issue could be closed now. To check if the problem is still there I need to set alpha != 1 to get a non-trivial solution; the results appear to be consistent now (whether transforming the full matrix, or one sample at a time).
import numpy as np
from sklearn.decomposition import SparsePCA
rnd = np.random.RandomState(0)
X = 2 * rnd.uniform(size=(5, 2))
y = X[:, 0].astype(np.int)
spca = SparsePCA(alpha=0.5)
spca.fit(X,y)
res_all = spca.transform(X)
res_one = np.array([spca.transform(X[i].reshape(1, X.shape[1]))[0]
for i in range(X.shape[0])])
print(res_all)
print(res_one)
Activity
jnothman commentedon Jan 8, 2018
[-]SparsePCA inconsistant on sub-sample[/-][+]SparsePCA inconsistent on sub-sample[/+]krassowski commentedon Mar 23, 2020
I think that maybe this issue could be closed now. To check if the problem is still there I need to set
alpha != 1to get a non-trivial solution; the results appear to be consistent now (whether transforming the full matrix, or one sample at a time).Result:
I think that it was fixed by #11585
Is the test from #10428 still failing?
thomasjpfan commentedon May 23, 2020
Thank you for testing @krassowski. This issue can be closed along with allowing the test to run on the
SparsePCAandMiniBatchSparsePCAestimators.