rsteca / sklearn-deap

Use evolutionary algorithms instead of gridsearch in scikit-learn
MIT License
771 stars 131 forks source link

deap #48

Closed maruwil closed 3 years ago

maruwil commented 6 years ago

Hi, I'm having some problems regarding "import deap". Wondering if you had similar problem or know how to fix? :)

The problem starts with a line in deap/base.py:

Traceback (most recent call last): File "assignment1.py", line 17, in from sklearn_deap.evolutionary_search import EvolutionaryAlgorithmSearchCV File "/home/user/anaconda3/lib/python3.5/site-packages/sklearn_deap/evolutionary_search/init.py", line 1, in from .cv import * File "/home/user/anaconda3/lib/python3.5/site-packages/sklearn_deap/evolutionary_search/cv.py", line 8, in from deap import base, creator, tools, algorithms File "/home/user/anaconda3/lib/python3.5/site-packages/deap/base.py", line 188 raise TypeError, ("Both weights and assigned values must be a " ^ SyntaxError: invalid syntax

I dont really understand this syntax, if it is wrong or not. I tried removing it. It managed to pass it and then got error regarding print statement (python 2 syntax without parentheses). So I did 2to3 on the code in deap library and now I get this error:

/home/user/anaconda3/lib/python3.5/site-packages/deap/tools/_hypervolume/pyhv.py:33: ImportWarning: Falling back to the python version of hypervolume module. Expect this to be very slow. "module. Expect this to be very slow.", ImportWarning) Traceback (most recent call last): File "assignment1.py", line 250, in cv = EvolutionaryAlgorithmSearchCV(estimator=svm.SVC(), params=paramgrid, scoring="accuracy", cv=kf, verbose=1, population_size=50, gene_mutation_prob=0.10, gene_crossover_prob=0.5, tournament_size=3, generations_number=5, n_jobs=4) File "/home/user/anaconda3/lib/python3.5/site-packages/sklearn_deap/evolutionary_search/cv.py", line 305, in init creator.create("FitnessMax", base.Fitness, weights=(1.0,)) File "/home/user/anaconda3/lib/python3.5/site-packages/deap/creator.py", line 145, in create for obj_name, obj in kargs.iteritems(): AttributeError: 'dict' object has no attribute 'iteritems'

Any idea whats might be going on? :)

jCrompton commented 6 years ago

I dont know if this helps but it looks like the iteritems method on a dict in python3 is gone: https://stackoverflow.com/questions/10458437/what-is-the-difference-between-dict-items-and-dict-iteritems Try importing in an earlier version of python (python2.7 worked for me)

maruwil commented 6 years ago

Yeah it seems that could be the problem. I'm gonna change it and see if I can manage to get it running :)

Thanks!