Skip to content

Instantly share code, notes, and snippets.

@WanyingF
Created December 8, 2021 10:16
Show Gist options
  • Save WanyingF/c473023cc56e9797ee6542bde9780bcf to your computer and use it in GitHub Desktop.
Save WanyingF/c473023cc56e9797ee6542bde9780bcf to your computer and use it in GitHub Desktop.
 Example of defining search space of hyperparameters of classification models by using HyperOpt
from hyperopt import hp
space = hp.choice('classifier_type', [
    {
        'type': 'naive_bayes',
    },
    {
        'type': 'svm',
        'C': hp.lognormal('svm_C', 0, 1),
        'kernel': hp.choice('svm_kernel', [
            {'ktype': 'linear'},
            {'ktype': 'RBF', 'width': hp.lognormal('svm_rbf_width', 0, 1)},
            ]),
    },
    {
        'type': 'dtree',
        'criterion': hp.choice('dtree_criterion', ['gini', 'entropy']),
        'max_depth': hp.choice('dtree_max_depth',
            [None, hp.qlognormal('dtree_max_depth_int', 3, 1, 1)]),
        'min_samples_split': hp.qlognormal('dtree_min_samples_split', 2, 1, 1),
    },
    ])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment