Skip to content

Commit e6a02ec

Browse files
author
Rodrigo
committed
fixes compatibility with python3, solves issue #9
1 parent 0d23c44 commit e6a02ec

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

evolutionary_search/__init__.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ def _get_param_types_maxint(params):
3333
types - list of types for each parameter
3434
maxints - list of maximum integer for each particular gene in chromosome
3535
"""
36-
name_values = params.items()
36+
name_values = list(params.items())
3737
types = []
3838
for _, possible_values in name_values:
3939
if isinstance(possible_values[0], float):
4040
types.append(param_types.Numerical)
4141
else:
4242
types.append(param_types.Categorical)
43-
maxints = [len(possible_values)-1 for _, possible_values in name_values]
43+
maxints = [len(possible_values) - 1 for _, possible_values in name_values]
4444
return name_values, types, maxints
4545

4646

@@ -96,10 +96,10 @@ def _evalFunction(individual, searchobj, name_values, X, y, scorer, cv, iid, fit
9696
searchobj.num_evaluations += 1
9797
searchobj.score_cache[paramkey] = _score
9898
if searchobj.verbose and (searchobj.num_evaluations + searchobj.num_cache_hits) % searchobj.population_size == 0:
99-
print "Scoring evaluations: %d, Cache hits: %d, Total: %d" % (
100-
searchobj.num_evaluations, searchobj.num_cache_hits, searchobj.num_evaluations + searchobj.num_cache_hits)
99+
print("Scoring evaluations: %d, Cache hits: %d, Total: %d" % (
100+
searchobj.num_evaluations, searchobj.num_cache_hits, searchobj.num_evaluations + searchobj.num_cache_hits))
101101
if iid:
102-
score += _score*len(test)
102+
score += _score * len(test)
103103
n_test += len(test)
104104
else:
105105
score += _score
@@ -341,7 +341,7 @@ def _fit(self, X, y, parameter_dict):
341341
stats.register("max", np.max)
342342

343343
if self.verbose:
344-
print('--- Evolve in {0} possible combinations ---'.format(np.prod(np.array(maxints)+1)))
344+
print('--- Evolve in {0} possible combinations ---'.format(np.prod(np.array(maxints) + 1)))
345345

346346
pop, logbook = algorithms.eaSimple(pop, toolbox, cxpb=0.5, mutpb=0.2,
347347
ngen=self.generations_number, stats=stats,
@@ -352,10 +352,9 @@ def _fit(self, X, y, parameter_dict):
352352

353353
if self.verbose:
354354
print("Best individual is: %s\nwith fitness: %s" % (
355-
current_best_params_, current_best_score_)
356-
)
357-
print "Scoring evaluations: %d, Cache hits: %d, Total: %d" % (
358-
self.num_evaluations, self.num_cache_hits, self.num_evaluations + self.num_cache_hits)
355+
current_best_params_, current_best_score_))
356+
print("Scoring evaluations: %d, Cache hits: %d, Total: %d" % (
357+
self.num_evaluations, self.num_cache_hits, self.num_evaluations + self.num_cache_hits))
359358

360359
if current_best_score_ > self.best_score_:
361360
self.best_score_ = current_best_score_

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
setup(
66
name='sklearn-deap',
7-
version='0.1.3',
7+
version='0.1.4',
88
author='Rodrigo',
99
author_email='',
1010
description='Use evolutionary algorithms instead of gridsearch in scikit-learn.',
1111
url='https://github.com/rsteca/sklearn-deap',
12-
download_url='https://github.com/rsteca/sklearn-deap/tarball/0.1.3',
12+
download_url='https://github.com/rsteca/sklearn-deap/tarball/0.1.4',
1313
classifiers=[
1414
'Development Status :: 4 - Beta',
1515
'Programming Language :: Python :: 2',

0 commit comments

Comments
 (0)