rsteca / sklearn-deap

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

Can Not Import the EvolutionaryAlgorithmSearchCV Call #37

Open BernardOng opened 6 years ago

BernardOng commented 6 years ago

Using the exact code sample, when I ran the code, I get an import error.

Traceback (most recent call last): File "test.py", line 18, in from evolutionary_search import EvolutionaryAlgorithmSearchCV File "D:\Anaconda2\lib\site-packages\evolutionary_search__init__.py", line 1, in from .cv import * File "D:\Anaconda2\lib\site-packages\evolutionary_search\cv.py", line 6, in from deap import base, creator, tools, algorithms File "D:\Python\zillow\deap.py", line 25, in from evolutionary_search import EvolutionaryAlgorithmSearchCV ImportError: cannot import name EvolutionaryAlgorithmSearchCV

`import sklearn.datasets
import numpy as np
import random

data = sklearn.datasets.load_digits()
X = data["data"]
y = data["target"]

from sklearn.svm import SVC
from sklearn.model_selection import StratifiedKFold

paramgrid = {"kernel": ["rbf"],
             "C"     : np.logspace(-9, 9, num=25, base=10),
             "gamma" : np.logspace(-9, 9, num=25, base=10)}

random.seed(1)

from evolutionary_search import EvolutionaryAlgorithmSearchCV
cv = EvolutionaryAlgorithmSearchCV(estimator=SVC(),
                                   params=paramgrid,
                                   scoring="accuracy",
                                   cv=StratifiedKFold(n_splits=4),
                                   verbose=1,
                                   population_size=50,
                                   gene_mutation_prob=0.10,
                                   gene_crossover_prob=0.5,
                                   tournament_size=3,
                                   generations_number=5,
                                   n_jobs=4)
cv.fit(X, y)`
rsteca commented 6 years ago

Hi! Many people have reported having problems with this library in an Anaconda environment. How did you install sklearn-deap?

BernardOng commented 6 years ago

I installed per instruction as follows (I used Windows 10 and Anaconda, 2x on main, 3x on env): pip install sklearn-deap

I just also tried installing from a cloned source under git and it still created the same issue. I tried under Python v2.7.13 and Python v3.6.2 - same results. Is there a way around this?

rsteca commented 6 years ago

Maybe you can use a virtualenv environment instead of using anaconda?