Skip to content

Commit

Permalink
fixes compatibility with python3, solves issue rsteca#9
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo committed Aug 23, 2016
1 parent 0d23c44 commit e6a02ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
19 changes: 9 additions & 10 deletions evolutionary_search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ def _get_param_types_maxint(params):
types - list of types for each parameter
maxints - list of maximum integer for each particular gene in chromosome
"""
name_values = params.items()
name_values = list(params.items())
types = []
for _, possible_values in name_values:
if isinstance(possible_values[0], float):
types.append(param_types.Numerical)
else:
types.append(param_types.Categorical)
maxints = [len(possible_values)-1 for _, possible_values in name_values]
maxints = [len(possible_values) - 1 for _, possible_values in name_values]
return name_values, types, maxints


Expand Down Expand Up @@ -96,10 +96,10 @@ def _evalFunction(individual, searchobj, name_values, X, y, scorer, cv, iid, fit
searchobj.num_evaluations += 1
searchobj.score_cache[paramkey] = _score
if searchobj.verbose and (searchobj.num_evaluations + searchobj.num_cache_hits) % searchobj.population_size == 0:
print "Scoring evaluations: %d, Cache hits: %d, Total: %d" % (
searchobj.num_evaluations, searchobj.num_cache_hits, searchobj.num_evaluations + searchobj.num_cache_hits)
print("Scoring evaluations: %d, Cache hits: %d, Total: %d" % (
searchobj.num_evaluations, searchobj.num_cache_hits, searchobj.num_evaluations + searchobj.num_cache_hits))
if iid:
score += _score*len(test)
score += _score * len(test)
n_test += len(test)
else:
score += _score
Expand Down Expand Up @@ -341,7 +341,7 @@ def _fit(self, X, y, parameter_dict):
stats.register("max", np.max)

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

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

if self.verbose:
print("Best individual is: %s\nwith fitness: %s" % (
current_best_params_, current_best_score_)
)
print "Scoring evaluations: %d, Cache hits: %d, Total: %d" % (
self.num_evaluations, self.num_cache_hits, self.num_evaluations + self.num_cache_hits)
current_best_params_, current_best_score_))
print("Scoring evaluations: %d, Cache hits: %d, Total: %d" % (
self.num_evaluations, self.num_cache_hits, self.num_evaluations + self.num_cache_hits))

if current_best_score_ > self.best_score_:
self.best_score_ = current_best_score_
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

setup(
name='sklearn-deap',
version='0.1.3',
version='0.1.4',
author='Rodrigo',
author_email='',
description='Use evolutionary algorithms instead of gridsearch in scikit-learn.',
url='https://github.com/rsteca/sklearn-deap',
download_url='https://github.com/rsteca/sklearn-deap/tarball/0.1.3',
download_url='https://github.com/rsteca/sklearn-deap/tarball/0.1.4',
classifiers=[
'Development Status :: 4 - Beta',
'Programming Language :: Python :: 2',
Expand Down

0 comments on commit e6a02ec

Please sign in to comment.