base_models#

Methods for creating HSR base models.

class hsr4hci.base_models.BaseModelCreator[source]#

Wrapper class for creating new base model instances.

Example

>>> base_model_config = {
>>>     'module': 'sklearn.linear_model',
>>>     'class': 'LinearRegression',
>>>     'parameters': {'fit_intercept': False},
>>> }
>>> bmc = BaseModelCreator(**base_model_config)
>>> model = bmc.get_model_instance()
>>> model
LinearRegression(fit_intercept=False)

Note

Ideally, this function should simply take three arguments instead of a dictionary. The reason behind the current version is a poor early design choice for the experiment configuration files: The โ€œclassโ€ parameter should have been called โ€œnameโ€ instead, because class is a protected key word in Python that cannot be used as the name of an input parameter. However, changing this now would require updating all experiment configuration files and all training scriptsโ€ฆ

__init__(**base_model_config)[source]#
Parameters:

**base_model_config (Any) โ€“

A dict containing the configuration of the base model. It needs to have exactly three keys (see example above):

  • module: A string with the module from which the base model should be imported.

  • class: A string with the class (= name) of the base model.

  • parameters: A dictionary with additional keyword arguments that will be passed to the constructor of module.class. Can be empty: {}.

Return type:

None

get_model_instance()[source]#

Get a new instance of the base model defined in the config.

Returns:

An instance of a regression method (e.g., from sklearn) that must provide the .fit() and .predict() methods.

Return type:

RegressorModel