gfdl.model.GFDLClassifier#

class GFDLClassifier(hidden_layer_sizes: ArrayLike = (100,), activation: str = 'identity', weight_scheme: str = 'uniform', direct_links: bool = True, seed: int = None, reg_alpha: float = None, rtol: float = None)[source]#

Bases: ClassifierMixin, GFDL

Random vector functional link network classifier.

This model fits a feedforward neural network with fixed random hidden-layer parameters and solves for the output weights using linear least squares or ridge regression. When direct links are disabled, the model architecture corresponds to an Extreme Learning Machine (ELM) architecture.

Parameters:
hidden_layer_sizesarray-like of shape (n_layers,), default=(100,)

The ith element represents the number of neurons in the ith hidden layer.

activationstr, default=’identity’

Activation function for the hidden layers.

  • ‘identity’, no-op activation, useful to implement linear bottleneck, returns f(x) = x

  • ‘tanh’: tanh.

  • ‘relu’: relu.

  • ‘sigmoid’: sigmoid.

  • ‘softmax’: softmax.

  • ‘softmin’: softmin.

  • ‘log_sigmoid’: log_sigmoid.

  • ‘log_softmax’: log_softmax.

weight_schemestr, default=’uniform’

Distribution used to initialize the random hidden-layer weights.

The initialization functions generate weight matrices of shape (n_hidden_units, n_features), where values are drawn according to the selected scheme.

  • ‘zeros’: set weights to zeros (zeros).

  • ‘range’: set weights to normalized np.arange (range).

  • ‘uniform’: uniform distribution (uniform).

  • ‘he_uniform’: He uniform distribution (he_uniform).

  • ‘lecun_uniform’: Lecun uniform distribution (lecun_uniform).

  • ‘glorot_uniform’: Glorot uniform distribution (glorot_uniform).

  • ‘normal’: Normal distribution (normal).

  • ‘he_normal’: He normal distribution (he_normal).

  • ‘lecun_normal’: Lecun normal distribution (lecun_normal).

  • ‘glorot_normal’: Glorot normal distribution (glorot_normal).

direct_linksbool, default=True

Whether to connect input layer to output nodes. When set to False, only the hidden-layer activations are used, corresponding to the Extreme Learning Machine (ELM) architecture.

seedint, RandomState instance, default=None

Determines random number generation for weights and bias initialization. Pass an int for reproducible results across multiple function calls. See Glossary.

reg_alphafloat, default=None

Amount of ridge shrinkage to apply in order to improve conditioning during Ridge regression. When set to zero or None, model uses direct solve using Moore-Penrose Pseudo-Inverse.

rtolfloat, default=None

Cutoff for small singular values for the Moore-Penrose pseudo-inverse. Only applies when reg_alpha=None. When rtol=None, the array API standard default for pinv is used.

Attributes:
n_features_in_int

Number of features seen during fit.

classes_ndarray or list of ndarray of shape (n_classes,)

Class labels for each output.

W_list of ndarray of shape (n_layers,)

Weight matrices of the hidden layers. The ith element in the list represents the weight matrix corresponding to layer i.

b_list of ndarray of shape (n_layers,)

Bias vectors of the hidden layers. The ith element in the list represents the bias term corresponding to layer i.

coeff_ndarray of shape (n_features_out, n_outputs)

Output weight matrix learned by fit method.

Methods

fit(X, y)

Build a gradient-free neural network from the training set (X, y).

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

predict(X)

Predict class for X.

predict_proba(X)

Predict class probabilities for X.

score(X, y[, sample_weight])

Return accuracy on provided data and labels.

set_params(**params)

Set the parameters of this estimator.

set_score_request(*[, sample_weight])

Configure whether metadata should be requested to be passed to the score method.

get_generator

See also

GFDLRegressor

Regressor variant for the RVFL architecture.

Examples

>>> from gfdl.model import GFDLClassifier
>>> from sklearn.datasets import make_classification
>>> from sklearn.model_selection import train_test_split
>>> X, y = make_classification(n_samples=100, random_state=1)
>>> X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y,
...                                                     random_state=1)
>>> clf = GFDLClassifier(seed=1).fit(X_train, y_train)
>>> clf.predict_proba(X_test[:1])
array([[0.46123716, 0.53876284]])
>>> clf.predict(X_test[:5, :])
array([1, 0, 1, 0, 1])
__init__(hidden_layer_sizes: ArrayLike = (100,), activation: str = 'identity', weight_scheme: str = 'uniform', direct_links: bool = True, seed: int = None, reg_alpha: float = None, rtol: float = None)[source]#

Methods

__init__([hidden_layer_sizes, activation, ...])

fit(X, y)

Build a gradient-free neural network from the training set (X, y).

get_generator(seed)

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

predict(X)

Predict class for X.

predict_proba(X)

Predict class probabilities for X.

score(X, y[, sample_weight])

Return accuracy on provided data and labels.

set_params(**params)

Set the parameters of this estimator.

set_score_request(*[, sample_weight])

Configure whether metadata should be requested to be passed to the score method.

fit(X, y)[source]#

Build a gradient-free neural network from the training set (X, y).

Parameters:
Xarray-like of shape (n_samples, n_features)

The training input samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

The target values (class labels).

Returns:
object

Fitted estimator.

get_metadata_routing()#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)#

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

predict(X)[source]#

Predict class for X.

Parameters:
Xarray-like of shape (n_samples, n_features)

The input samples.

Returns:
ndarray

The predicted classes, with shape (n_samples,) or (n_samples, n_outputs).

predict_proba(X)[source]#

Predict class probabilities for X.

Parameters:
Xarray-like of shape (n_samples, n_features)

The input samples.

Returns:
ndarray

The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_. The ndarray should have shape (n_samples, n_classes).

score(X, y, sample_weight=None)#

Return accuracy on provided data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True labels for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

Mean accuracy of self.predict(X) w.r.t. y.

set_params(**params)#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') GFDLClassifier#

Configure whether metadata should be requested to be passed to the score method.

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 (see sklearn.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 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.

Added in version 1.3.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.