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: pyrcn.base.blocks._input_to_node.InputToNode | None = None, regressor: pyrcn.linear_model._incremental_regression.IncrementalRegression | sklearn.base.RegressorMixin | None = None, chunk_size: int | None = None, verbose: bool = False, **kwargs: Any)¶
Bases:
RegressorMixin,MultiOutputMixin,BaseEstimatorExtreme 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, RegressorMixin, None],) –
default=None – Regressor object such as derived from
RegressorMixin. 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: None | int | numpy.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: int | numpy.integer | None = None, transformer_weights: numpy.ndarray | None = 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.
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
- partial_fit(X: ndarray, y: ndarray, transformer_weights: numpy.ndarray | None = 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: sklearn.base.RegressorMixin | pyrcn.linear_model._incremental_regression.IncrementalRegression¶
Return the regressor.
- Returns
regressor
- Return type
RegressorMixin
- set_fit_request(*, n_jobs: Union[bool, None, str] = '$UNCHANGED$', transformer_weights: Union[bool, None, str] = '$UNCHANGED$') ELMRegressor¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.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.
- Parameters
n_jobs (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
n_jobsparameter infit.transformer_weights (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
transformer_weightsparameter infit.
- 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¶
Configure whether metadata should be requested to be passed to the
partial_fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topartial_fitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topartial_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.
- Parameters
postpone_inverse (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
postpone_inverseparameter inpartial_fit.transformer_weights (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
transformer_weightsparameter inpartial_fit.
- Returns
self – The updated object.
- Return type
object
- set_score_request(*, sample_weight: Union[bool, None, str] = '$UNCHANGED$') ELMRegressor¶
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.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.
- Parameters
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.- Returns
self – The updated object.
- Return type
object
- class pyrcn.extreme_learning_machine.ELMClassifier(*, input_to_node: pyrcn.base.blocks._input_to_node.InputToNode | None = None, regressor: pyrcn.linear_model._incremental_regression.IncrementalRegression | sklearn.base.RegressorMixin | None = None, chunk_size: int | None = None, verbose: bool = False, **kwargs: Any)¶
Bases:
ClassifierMixin,ELMRegressorExtreme 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, RegressorMixin, None],) –
default=None – Regressor object such as derived from
RegressorMixin. 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: int | numpy.integer | None = None, transformer_weights: numpy.ndarray | None = 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: numpy.ndarray | None = None, postpone_inverse: bool = False, classes: numpy.ndarray | None = 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¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.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.
- Parameters
n_jobs (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
n_jobsparameter infit.transformer_weights (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
transformer_weightsparameter infit.
- 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¶
Configure whether metadata should be requested to be passed to the
partial_fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topartial_fitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topartial_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.
- Parameters
classes (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
classesparameter inpartial_fit.postpone_inverse (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
postpone_inverseparameter inpartial_fit.transformer_weights (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
transformer_weightsparameter inpartial_fit.
- Returns
self – The updated object.
- Return type
object
- set_score_request(*, sample_weight: Union[bool, None, str] = '$UNCHANGED$') ELMClassifier¶
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.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.
- Parameters
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.- Returns
self – The updated object.
- Return type
object