hibou.nn.ModelSet#
- class hibou.nn.ModelSet(*args, nb_models: int = 50, model_generator: Callable = None, no_init: bool = False, **kwargs)#
This class allows you to consider several identical models and use them as a single one.
Parameters#
- args
The positionnal arguments to be given to
model_generator.- kwargs
The keyword arguments to be given to
model_generator.- nb_models
int, optionnal, keyword-only By default:
50. The number of models to consider.- model_generator
Callable, keyword-only By default:
default_model. A function that takes in arguments the hyperparameters and returns the compiled model.
Methods#
- __call__(*args, **kwargs)#
Implements the call to a model to obtain the prediction.
Parameters#
- args
The positionnal arguments to be given when the model is called.
- kwargs
The keyword arguments to be given when the model is called.
Returns#
np.arrayA NumPy array that contains the results of the call in two columns:
(prediction, probability). The first dimension is the model.
- __getitem__(index: int)#
Returns the model at the given index.
Parameters#
- index
int The index of the wanted model.
Returns#
keras.models.SequentialThe model at the given index.
- index
- fit(**kwargs)#
Implements the
Model.fitmethod. You can useModelSet.fitexactly askeras.Model.fit, and ditto forModelSet.evaluate.Parameters#
- args
The positionnal arguments to be given to
fit.- kwargs
The keyword arguments to be given to
fit.
- evaluate(**kwargs)#
Implements the
Model.evaluatemethod. You can useModelSet.evaluateexactly askeras.Model.evaluate. It also implements a basic filter on the models in the set. Models with too high loss or too low correlation will be ignored for prediction and deleted from the model list. The number of kept model is available in logs or you can access it via:len(my_modelset.models).Note
Losses and correlations are calculated for each model during evaluation.
Parameters#
- args
The positionnal arguments to be given to
evaluate.- std
float, optionnal, keywork-only By default:
2. The number of standard deviations used to define the limits of accepted models. For exemple, ifstdis set on 2 (the default value), all the models with a correlation coefficient under the mean correlation minus two standard deviations will be deleted.- kwargs
The keyword arguments to be given to
evaluate.
Examples#
A basic example:
# creating a list of ten models with default parameters my_list = ModelSet(nb_models=10) # train the list my_list.fit(x_train, y_train, epochs=100) # evaluate the list my_list.evaluate(x_test, y_test) # use the list result = my_list(inputs) estimates, probabilities = result[:, 0], result[:, 1]