Deep Extreme Learning Machine (Deep ELM) Model.
This class implements a Deep ELM model, which is a variant of the Extreme Learning Machine (ELM) that
incorporates multiple layers. Each layer of the Deep ELM model consists of an ELM layer.
Parameters:
-----------
classification (bool, optional): Whether the task is classification or regression.
Defaults to True.
layers (list, optional): List of ELMLayer objects representing the layers of the model.
Defaults to None.
verbose (int, optional): Verbosity level (0 for silent, 1 for progress bar).
Defaults to 0.
Attributes:
-----------
classes_ (array-like): Unique class labels.
classification (bool): Indicates whether the task is classification or regression.
layers (list): List of ELMLayer objects representing the layers of the model.
verbose (int): Verbosity level.
Methods:
-----------
add(layer): Add an ELMLayer to the model.
fit(X, y): Fit the Deep ELM model to training data.
predict(X): Predict class labels or regression values for input data.
predict_proba(X): Predict class probabilities for input data.
summary(): Print a summary of the model architecture.
to_dict(): Convert the model to a dictionary of attributes.
save(file_path): Serialize the model and save it to an HDF5 file.
load(file_path): Deserialize a model instance from an HDF5 file.
Example:
-----------
Initialize a ReceptiveFieldGenerator with input size (28, 28, 1) and 10 output classes
>>> rf = ReceptiveFieldGenerator(input_size=(28, 28, 1), num_classes=10)
Initialize a DeepELMModel
>>> model = DeepELMModel()
Add ELMLayers to the model with different numbers of neurons and the same receptive field generator
The receptive field generator ensures that each layer has the same receptive field configuration
>>> model.add(ELMLayer(number_neurons=1000, receptive_field_generator=rf))
>>> model.add(ELMLayer(number_neurons=2000, receptive_field_generator=rf))
>>> model.add(ELMLayer(number_neurons=1000, receptive_field_generator=rf))
Define a cross-validation strategy
>>> cv = RepeatedKFold(n_splits=n_splits, n_repeats=n_repeats)
Perform cross-validation to evaluate the model performance
>>> scores = cross_val_score(model, X, y, cv=cv, scoring='accuracy', error_score='raise')
Print the mean accuracy score obtained from cross-validation
>>> print(np.mean(scores))
Fit the ELM model to the entire dataset
>>> model.fit(X, y)
Save the trained model to a file
>>> model.save("Saved Models/DeepELM_Model.h5")
Load the saved model from the file
>>> model = model.load("Saved Models/DeepELM_Model.h5")
Evaluate the accuracy of the model on the training data
>>> acc = accuracy_score(model.predict(X), y)
DeepELMModel.DeepELMModel.fit |
( |
| self, |
|
|
| x, |
|
|
| y ) |
Fit the Deep ELM model to training data.
Parameters:
-----------
x (array-like): Training input samples.
y (array-like): Target values.
Example:
-----------
Initialize a ReceptiveFieldGenerator with input size (28, 28, 1) and 10 output classes
>>> rf = ReceptiveFieldGenerator(input_size=(28, 28, 1), num_classes=10)
Initialize a DeepELMModel
>>> model = DeepELMModel()
Add ELMLayers to the model with different numbers of neurons and the same receptive field generator
The receptive field generator ensures that each layer has the same receptive field configuration
>>> model.add(ELMLayer(number_neurons=1000, receptive_field_generator=rf))
>>> model.add(ELMLayer(number_neurons=2000, receptive_field_generator=rf))
>>> model.add(ELMLayer(number_neurons=1000, receptive_field_generator=rf))
Fit the ELM model to the entire dataset
>>> model.fit(X, y)
DeepELMModel.DeepELMModel.load |
( |
| cls, |
|
|
str | file_path ) |
Deserialize a model instance from an HDF5 file.
Parameters:
-----------
file_path (str): The file path from which to load the serialized instance.
Returns:
-----------
DeepELMModel: An instance of the DeepELMModel class loaded from the file.
Example:
-----------
Initialize a ReceptiveFieldGenerator with input size (28, 28, 1) and 10 output classes
>>> rf = ReceptiveFieldGenerator(input_size=(28, 28, 1), num_classes=10)
Initialize a DeepELMModel
>>> model = DeepELMModel()
Add ELMLayers to the model with different numbers of neurons and the same receptive field generator
The receptive field generator ensures that each layer has the same receptive field configuration
>>> model.add(ELMLayer(number_neurons=1000, receptive_field_generator=rf))
>>> model.add(ELMLayer(number_neurons=2000, receptive_field_generator=rf))
>>> model.add(ELMLayer(number_neurons=1000, receptive_field_generator=rf))
Load the saved model from the file
>>> model = DeepELMModel.load("Saved Models/ELM_Model.h5")
DeepELMModel.DeepELMModel.predict |
( |
| self, |
|
|
| x ) |
Predict class labels or regression values for input data.
Parameters:
-----------
x (array-like): Input samples.
Returns:
-----------
array-like: Predicted class labels or regression values.
Example:
-----------
Initialize a ReceptiveFieldGenerator with input size (28, 28, 1) and 10 output classes
>>> rf = ReceptiveFieldGenerator(input_size=(28, 28, 1), num_classes=10)
Initialize a DeepELMModel
>>> model = DeepELMModel()
Add ELMLayers to the model with different numbers of neurons and the same receptive field generator
The receptive field generator ensures that each layer has the same receptive field configuration
>>> model.add(ELMLayer(number_neurons=1000, receptive_field_generator=rf))
>>> model.add(ELMLayer(number_neurons=2000, receptive_field_generator=rf))
>>> model.add(ELMLayer(number_neurons=1000, receptive_field_generator=rf))
Fit the ELM model to the entire dataset
>>> model.fit(X, y)
Evaluate the accuracy of the model on the training data
>>> acc = accuracy_score(model.predict(X), y)
DeepELMModel.DeepELMModel.predict_proba |
( |
| self, |
|
|
| x ) |
Predict class probabilities for input data.
Parameters:
-----------
x (array-like): Input samples.
Returns:
-----------
array-like: Predicted class probabilities.
Example:
-----------
Initialize a ReceptiveFieldGenerator with input size (28, 28, 1) and 10 output classes
>>> rf = ReceptiveFieldGenerator(input_size=(28, 28, 1), num_classes=10)
Initialize a DeepELMModel
>>> model = DeepELMModel()
Add ELMLayers to the model with different numbers of neurons and the same receptive field generator
The receptive field generator ensures that each layer has the same receptive field configuration
>>> model.add(ELMLayer(number_neurons=1000, receptive_field_generator=rf))
>>> model.add(ELMLayer(number_neurons=2000, receptive_field_generator=rf))
>>> model.add(ELMLayer(number_neurons=1000, receptive_field_generator=rf))
Fit the ELM model to the entire dataset
>>> model.fit(X, y)
Evaluate the accuracy of the model on the training data
>>> pred_proba = model.predict_proba(X)
DeepELMModel.DeepELMModel.save |
( |
| self, |
|
|
| file_path ) |
Serialize the current instance and save it to a HDF5 file.
Parameters:
-----------
- path (str): The file path where the serialized instance will be saved.
Returns:
-----------
None
Example:
-----------
Initialize a ReceptiveFieldGenerator with input size (28, 28, 1) and 10 output classes
>>> rf = ReceptiveFieldGenerator(input_size=(28, 28, 1), num_classes=10)
Initialize a DeepELMModel
>>> model = DeepELMModel()
Add ELMLayers to the model with different numbers of neurons and the same receptive field generator
The receptive field generator ensures that each layer has the same receptive field configuration
>>> model.add(ELMLayer(number_neurons=1000, receptive_field_generator=rf))
>>> model.add(ELMLayer(number_neurons=2000, receptive_field_generator=rf))
>>> model.add(ELMLayer(number_neurons=1000, receptive_field_generator=rf))
Save the trained model to a file
>>> model.save("Saved Models/ELM_Model.h5")