Muestreo de combinaciones de hiperparámetros con ParameterSampler#

[1]:
import numpy as np
import scipy
from sklearn.model_selection import ParameterSampler

param_distributions = [
    # -------------------------------------------------------------------------
    # Selección aleatoria de valores para el primer modelo
    {
        "kernel": ["rbf"],
        "gamma": scipy.stats.expon(scale=0.1),
        "C": scipy.stats.expon(scale=100),
    },
    # -------------------------------------------------------------------------
    # Selección aleatoria de valores para el segundo modelo
    {
        "kernel": ["linear"],
        "C": [1, 10, 100],
    },
]

params = ParameterSampler(
    # -------------------------------------------------------------------------
    param_distributions=param_distributions,
    n_iter=10,
    random_state=12345,
)

result = [dict((k, v) for (k, v) in d.items()) for d in params]

result
[1]:
[{'C': 220.8682396496381, 'gamma': 0.014007538087890578, 'kernel': 'rbf'},
 {'C': 100, 'kernel': 'linear'},
 {'C': 83.86933864671792, 'gamma': 0.09052140627545172, 'kernel': 'rbf'},
 {'C': 61.97597554687909, 'gamma': 0.2573582562354472, 'kernel': 'rbf'},
 {'C': 100, 'kernel': 'linear'},
 {'C': 222.88118074128667, 'gamma': 0.0027155110061623483, 'kernel': 'rbf'},
 {'C': 11.254669304411362, 'gamma': 0.03548248190035313, 'kernel': 'rbf'},
 {'C': 10, 'kernel': 'linear'},
 {'C': 81.28259452454746, 'gamma': 0.18320769168351672, 'kernel': 'rbf'},
 {'C': 1, 'kernel': 'linear'}]