pyrcn.extreme_learning_machine

The pyrcn.extreme_learning_machine.

It contains a simple object-oriented implementation of Extreme Learning Machines 1.

Separate implementations of Classifiers and Regressors as specified by scikit-learn.

References

1

Guang-Bin Huang et al., ‘Extreme learning machine: Theory and applications’, p. 489-501, 2006, doi: 10.1016/j.neucom.2005.12.126.

class pyrcn.extreme_learning_machine.ELMRegressor(*, input_to_node: Optional[InputToNode] = None, regressor: Optional[Union[IncrementalRegression, LinearModel]] = None, chunk_size: Optional[int] = None, verbose: bool = False, **kwargs: Any)

Bases: BaseEstimator, MultiOutputMixin, RegressorMixin

Extreme Learning Machine regressor.

This model optimizes the mean squared error loss function using linear regression.

Parameters
  • input_to_node (Optional[InputToNode], default=None) – Any `InputToNode` object that transforms the inputs. If `None`, a `pyrcn.base.blocks.InputToNode` object is instantiated.

  • regressor (Union[IncrementalRegression, LinearModel, None], default=None) – Regressor object such as derived from LinearModel. This regressor will automatically be cloned each time prior to fitting. If `None`, a `pyrcn.linear_model.IncrementalRegression` object is instantiated.

  • chunk_size (Optional[int], default=None) – if X.shape[0] > chunk_size, calculate results incrementally with partial_fit

  • verbose (bool = False) – Verbosity output

  • kwargs (Any, default = None) – keyword arguments passed to the subestimators if this is desired, default=None

property chunk_size: Union[None, int, integer]

Return the chunk_size, in which X will be chopped.

Returns

chunk_size

Return type

Union[int, np.integer]

fit(X: ndarray, y: ndarray, n_jobs: Optional[Union[int, integer]] = None, transformer_weights: Optional[ndarray] = None) ELMRegressor

Fit the regressor.

Parameters
  • X (ndarray of shape (n_samples, n_features)) –

  • y (ndarray of shape (n_samples,) or (n_samples, n_targets)) – The targets to predict.

  • n_jobs (int, default=None) – The number of jobs to run in parallel. `-1` means using all processors. See Glossary for more details.

  • transformer_weights (Union[np.ndarray, None], default=None) – ignored

Returns

self

Return type

Returns a trained ELMRegressor model.

get_params(deep: bool = True) dict

Get all parameters of the ESNRegressor.

hidden_layer_state(X: ndarray) ndarray

Return the hidden_layer_state, e.g. the reservoir state over time.

Parameters

X (ndarray of shape (n_samples, n_features)) –

Returns

hidden_layer_state – The hidden_layer_state, e.g. the reservoir state over time.

Return type

ndarray of (n_samples,)

property input_to_node: InputToNode

Return the input_to_node Estimator.

Returns

input_to_node

Return type

InputToNode

partial_fit(X: ndarray, y: ndarray, transformer_weights: Optional[ndarray] = None, postpone_inverse: bool = False) ELMRegressor

Fit the regressor partially.

Parameters
  • X (ndarray of shape (n_samples, n_features)) –

  • y (ndarray of shape (n_samples,) or (n_samples, n_targets)) – The targets to predict.

  • transformer_weights (Union[np.ndarray, None], default=None) – ignored

  • postpone_inverse (bool, default=False) – If the output weights have not been fitted yet, regressor might be hinted at postponing inverse calculation. Refer to `IncrementalRegression` for details.

Returns

self

Return type

Returns a trained `ELMRegressor` model.

predict(X: ndarray) ndarray

Predict the targets using the trained `ELMRegressor`.

Parameters

X (ndarray of shape (n_samples, n_features)) –

Returns

y – The predicted targets

Return type

ndarray of (n_samples,) or (n_samples, n_targets)

property regressor: Union[LinearModel, IncrementalRegression]

Return the regressor.

Returns

regressor

Return type

LinearModel

set_fit_request(*, n_jobs: Union[bool, None, str] = '$UNCHANGED$', transformer_weights: Union[bool, None, str] = '$UNCHANGED$') ELMRegressor

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters
  • n_jobs (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for n_jobs parameter in fit.

  • transformer_weights (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for transformer_weights parameter in fit.

Returns

self – The updated object.

Return type

object

set_params(**parameters: dict) ELMRegressor

Set all possible parameters of the ELMRegressor.

set_partial_fit_request(*, postpone_inverse: Union[bool, None, str] = '$UNCHANGED$', transformer_weights: Union[bool, None, str] = '$UNCHANGED$') ELMRegressor

Request metadata passed to the partial_fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to partial_fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to partial_fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters
  • postpone_inverse (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for postpone_inverse parameter in partial_fit.

  • transformer_weights (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for transformer_weights parameter in partial_fit.

Returns

self – The updated object.

Return type

object

set_score_request(*, sample_weight: Union[bool, None, str] = '$UNCHANGED$') ELMRegressor

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters

sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in score.

Returns

self – The updated object.

Return type

object

class pyrcn.extreme_learning_machine.ELMClassifier(*, input_to_node: Optional[InputToNode] = None, regressor: Optional[Union[IncrementalRegression, LinearModel]] = None, chunk_size: Optional[int] = None, verbose: bool = False, **kwargs: Any)

Bases: ELMRegressor, ClassifierMixin

Extreme Learning Machine classifier.

This model optimizes the mean squared error loss function using linear regression.

Parameters
  • input_to_node (Optional[InputToNode], default=None) – Any `InputToNode` object that transforms the inputs. If `None`, a `pyrcn.base.blocks.InputToNode` object is instantiated.

  • regressor (Union[IncrementalRegression, LinearModel, None], default=None) – Regressor object such as derived from LinearModel. This regressor will automatically be cloned each time prior to fitting. If `None`, a `pyrcn.linear_model.IncrementalRegression` object is instantiated.

  • chunk_size (Optional[int], default=None) – if X.shape[0] > chunk_size, calculate results incrementally with partial_fit

  • verbose (bool = False) – Verbosity output

  • kwargs (Any, default = None) – keyword arguments passed to the subestimators if this is desired, default=None

fit(X: ndarray, y: ndarray, n_jobs: Optional[Union[int, integer]] = None, transformer_weights: Optional[ndarray] = None) ELMClassifier

Fit the classifier.

Parameters
  • X (ndarray of shape (n_samples, n_features)) –

  • y (ndarray of shape (n_samples,) or (n_samples, n_classes)) – The targets to predict.

  • n_jobs (Union[int, np.integer, None], default=None) – The number of jobs to run in parallel. `-1` means using all processors. See Glossary for more details.

  • transformer_weights (Optional[np.ndarray], default=None) – ignored

Returns

self

Return type

Returns a trained ELMClassifier model.

partial_fit(X: ndarray, y: ndarray, transformer_weights: Optional[ndarray] = None, postpone_inverse: bool = False, classes: Optional[ndarray] = None) ELMClassifier

Fit the classifier partially.

Parameters
  • X (ndarray of shape (n_samples, n_features)) –

  • y (ndarray of shape (n_samples,) or (n_samples, n_classes)) – The targets to predict.

  • classes (Optional[ndarray] of shape (n_classes,), default=None) – Classes across all calls to partial_fit. Can be obtained via np.unique(y_all), where y_all is the target vector of the entire dataset. This argument is required for the first call to partial_fit and can be omitted in the subsequent calls. Note that y doesn’t need to contain all labels in classes.

  • transformer_weights (Optional[ndarray], default=None) – ignored

  • postpone_inverse (bool, default=False) – If the output weights have not been fitted yet, regressor might be hinted at postponing inverse calculation. Refer to `IncrementalRegression` for details.

Returns

self

Return type

returns a trained ELMClassifier model

predict(X: ndarray) ndarray

Predict the classes using the trained `ELMClassifier`.

Parameters

X (ndarray of shape (n_samples, n_features)) – The input data.

Returns

y_pred – The predicted classes.

Return type

ndarray of shape (n_samples,) or (n_samples, n_classes)

predict_log_proba(X: ndarray) ndarray

Predict the log probability estimated using a trained `ELMClassifier`.

Parameters

X (ndarray of shape (n_samples, n_features)) – The input data.

Returns

y_pred – The predicted logarithmic probability estimated.

Return type

ndarray of shape (n_samples,) or (n_samples, n_classes)

predict_proba(X: ndarray) ndarray

Predict the probability estimated using a trained `ELMClassifier`.

Parameters

X (ndarray of shape (n_samples, n_features)) – The input data.

Returns

y_pred – The predicted probability estimates.

Return type

ndarray of shape (n_samples,) or (n_samples, n_classes)

set_fit_request(*, n_jobs: Union[bool, None, str] = '$UNCHANGED$', transformer_weights: Union[bool, None, str] = '$UNCHANGED$') ELMClassifier

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters
  • n_jobs (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for n_jobs parameter in fit.

  • transformer_weights (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for transformer_weights parameter in fit.

Returns

self – The updated object.

Return type

object

set_partial_fit_request(*, classes: Union[bool, None, str] = '$UNCHANGED$', postpone_inverse: Union[bool, None, str] = '$UNCHANGED$', transformer_weights: Union[bool, None, str] = '$UNCHANGED$') ELMClassifier

Request metadata passed to the partial_fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to partial_fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to partial_fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters
  • classes (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for classes parameter in partial_fit.

  • postpone_inverse (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for postpone_inverse parameter in partial_fit.

  • transformer_weights (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for transformer_weights parameter in partial_fit.

Returns

self – The updated object.

Return type

object

set_score_request(*, sample_weight: Union[bool, None, str] = '$UNCHANGED$') ELMClassifier

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters

sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in score.

Returns

self – The updated object.

Return type

object