8000 Fix n_components=None not being handled in MiniBatchDictionaryLearnin… · scikit-learn/scikit-learn@e37f56a · GitHub
[go: up one dir, main page]

Skip to content

Commit e37f56a

Browse files
committed
Fix n_components=None not being handled in MiniBatchDictionaryLearning.partial_fit
1 parent f91dee7 commit e37f56a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

sklearn/decomposition/dict_learning.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ def dict_learning(X, n_components, alpha, max_iter=100, tol=1e-8,
412412
SparsePCA
413413
MiniBatchSparsePCA
414414
"""
415+
if n_components is None:
416+
n_components = X.shape[1]
415417

416418
if method not in ('lars', 'cd'):
417419
raise ValueError('Coding method %r not supported as a fit algorithm.'
@@ -750,7 +752,7 @@ def transform(self, X, y=None):
750752
Transformed data
751753
752754
"""
753-
check_is_fitted(self, 'components_')
755+
check_is_fitted(self, 'components_')
754756

755757
# XXX : kwargs is not documented
756758
X = check_array(X)
@@ -1159,13 +1161,9 @@ def fit(self, X, y=None):
11591161
"""
11601162
random_state = check_random_state(self.random_state)
11611163
X = check_array(X)
1162-
if self.n_components is None:
1163-
n_components = X.shape[1]
1164-
else:
1165-
n_components = self.n_components
11661164

11671165
U, (A, B), self.n_iter_ = dict_learning_online(
1168-
X, n_components, self.alpha,
1166+
X, self.n_components, self.alpha,
11691167
n_iter=self.n_iter, return_code=False,
11701168
method=self.fit_algorithm,
11711169
n_jobs=self.n_jobs, dict_init=self.dict_init,

0 commit comments

Comments
 (0)
0