Skip to content

Commit afeb7ee

Browse files
committed
remove useless |samples| variable out of ParameterSampler.__iter__()
1 parent e1fd955 commit afeb7ee

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

sklearn/grid_search.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from abc import ABCMeta, abstractmethod
1414
from collections import Mapping, namedtuple, Sized
1515
from functools import partial, reduce
16-
from itertools import product
16+
from itertools import product, repeat
1717
import operator
1818
import warnings
1919

@@ -170,7 +170,6 @@ def __init__(self, param_distributions, n_iter, random_state=None):
170170
self.random_state = random_state
171171

172172
def __iter__(self):
173-
samples = []
174173
# check if all distributions are given as lists
175174
# in this case we want to sample without replacement
176175
all_lists = np.all([not hasattr(v, "rvs")
@@ -194,14 +193,13 @@ def __iter__(self):
194193
else:
195194
# Always sort the keys of a dictionary, for reproducibility
196195
items = sorted(self.param_distributions.items())
197-
while len(samples) < self.n_iter:
196+
for _ in repeat(None, self.n_iter):
198197
params = dict()
199198
for k, v in items:
200199
if hasattr(v, "rvs"):
201200
params[k] = v.rvs()
202201
else:
203202
params[k] = v[rnd.randint(len(v))]
204-
samples.append(params)
205203
yield params
206204

207205
def __len__(self):

0 commit comments

Comments
 (0)