Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimizing a loss function #49

Open
jCrompton opened this issue Feb 6, 2018 · 3 comments
Open

Minimizing a loss function #49

jCrompton opened this issue Feb 6, 2018 · 3 comments

Comments

@jCrompton
Copy link

Line 305 in cv.py, is there anyway we can change the weights tuple to minimize a loss function rather than always maximize ?

@jCrompton
Copy link
Author

basically I want to change creator.create("FitnessMax", base.Fitness, weights=(1.0,)) to creator.create("FitnessMax", base.Fitness, weights=(-1.0,))

@craymichael
Copy link

craymichael commented May 9, 2018

When creating the cv, you can wrap the scoring function parameter. For example:

from functools import wraps
from sklearn import accuracy_score
from evolutionary_search import EvolutionaryAlgorithmSearchCV
...
def wrap_score_func(score_func):
    @wraps(score_func)
    def wrapped(*args, **kwargs):
        return -score_func(*args, **kwargs)
    return wrapped
...
cv = EvolutionaryAlgorithmSearchCV(estimator=SVC(),
                                   params=paramgrid,
                                   scoring=wrap_score_func(accuracy_score),
                                   ...)

Ideally, this should just be a parameter during cv initialization.

@craymichael
Copy link

Created PR #51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants