Thanks to visit codestin.com
Credit goes to github.com

Skip to content

SparsePCA inconsistent on sub-sample #10431

@Johayon

Description

@Johayon

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

Steps/Code to Reproduce

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()
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

Linux-4.10.0-42-generic-x86_64-with-debian-stretch-sid
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 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions