btb.tuning.hyperparams.categorical module

Package where the CategoricalHyperParamClass is defined.

class btb.tuning.hyperparams.categorical.CategoricalHyperParam(choices, default=<object object>)[source]

Bases: btb.tuning.hyperparams.base.BaseHyperParam

CategoricalHyperParam Class.

The CategoricalHyperParam class is responsible for the transform of categorical values in to normalized search space and provides the inverse transform from search space to hyperparameter space. Also provides a method that generates samples of those.

Hyperparameter space:

\(h_1, h_2,... h_K\) where K is the number of categories.

Search Space:

\(\{ 0, 1 \}^K\) where K is the number of categories.

Parameters
  • choices (list) – List of values that the hyperparameter can be.

  • default (str or None) – Default value for the hyperparameter to take. Defaults to the first item in choices

NO_DEFAULT = <object object>
sample(n_samples)[source]

Generate sample values in the hyperparameter search space of [0, 1]^K.

Parameters

n_samples (int) – Number of values to sample.

Returns

2D array with shape of (n_samples, self.dimensions) with normalized values inside the search space \([0, 1]^K\).

Return type

numpy.ndarray

Example

The example below shows simple usage case where a CategoricalHyperParam is being created with three possible values, (Cat, Dog, Tiger), and it’s method sample is being called with a number of samples to be obtained. A numpy.ndarray with values from the search space is being returned.

>>> instance = CategoricalHyperParam(choices=['Cat', 'Dog', 'Tiger'])
>>> instance.sample(2)
array([[1, 0, 0],
       [0, 1, 0]])