TfELM
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
ELMModel.ELMModel Class Reference
Inheritance diagram for ELMModel.ELMModel:

Public Member Functions

 __init__ (self, layer, classification=True, random_weights=True)
 
 fit (self, X, y)
 
 predict (self, X)
 
 predict_proba (self, x)
 
 save (self, file_path)
 
 load (cls, str file_path)
 
 to_dict (self)
 

Public Attributes

 classes_
 
 classification
 
 layer
 
 random_weights
 

Detailed Description

Extreme Learning Machine model.

This class implements an Extreme Learning Machine (ELM) model, which is a single-hidden-layer feedforward neural
network. The model can be used for both classification and regression tasks.

Parameters:
-----------
layer : ELMLayer
    The hidden layer of the ELM model.
classification : bool, default=True
    Indicates whether the model is used for classification (True) or regression (False) tasks.
random_weights : bool, default=True
    Indicates whether to randomly initialize the weights of the hidden layer.

Attributes:
-----------
classes_ : array-like, shape (n_classes,)
    The unique class labels in the training data.

Examples:
-----------
Initialize an Extreme Learning Machine (ELM) layer with 1000 neurons

>>> elm = ELMLayer(number_neurons=1000, activation='mish')

Create an ELM model using the trained ELM layer

>>> model = ELMModel(elm)

Define a cross-validation strategy

>>> cv = RepeatedKFold(n_splits=10, n_repeats=50)

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/ELM_Model.h5")

Load the saved model from the file

>>> model = model.load("Saved Models/ELM_Model.h5")

Evaluate the accuracy of the model on the training data

>>> acc = accuracy_score(model.predict(X), y)
>>> print(acc)

Member Function Documentation

◆ fit()

ELMModel.ELMModel.fit ( self,
X,
y )
    Fit the ELM model to the training data.

    Parameters:
    -----------
    X : array-like, shape (n_samples, n_features)
        The input training data.
    y : array-like, shape (n_samples,) or (n_samples, n_classes)
        The target values for classification or regression tasks.

    Returns:
    --------
    self : object
        Returns the instance itself.

    Example:
    -----------
    Initialize an Extreme Learning Machine (ELM) layer with 1000 neurons

    >>> elm = ELMLayer(number_neurons=1000, activation='mish')

    Create an ELM model using the trained ELM layer

    >>> model = ELMModel(elm)

    Fit the ELM model to the entire dataset

    >>> model.fit(X, y)

◆ load()

ELMModel.ELMModel.load ( cls,
str file_path )
    Load a model from an HDF5 file.

    Parameters:
    -----------
    file_path : str
        The path to the HDF5 file containing the model.

    Returns:
    --------
    model : ELMModel
        The loaded ELMModel instance.

    Example:
    -----------
    Load the saved model from the file

    >>> model = ELMModel.load("Saved Models/ELM_Model.h5")

◆ predict()

ELMModel.ELMModel.predict ( self,
X )
    Predict class labels or regression values for the input data.

    Parameters:
    -----------
    X : array-like, shape (n_samples, n_features)
        The input data.

    Returns:
    --------
    y_pred : array-like, shape (n_samples,)
        The predicted class labels or regression values.

    Example:
    -----------
    Initialize an Extreme Learning Machine (ELM) layer with 1000 neurons

    >>> elm = ELMLayer(number_neurons=1000, activation='mish')

    Create an ELM model using the trained ELM layer

    >>> model = ELMModel(elm)

    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)

◆ predict_proba()

ELMModel.ELMModel.predict_proba ( self,
x )
    Predict class probabilities for the input data.

    Parameters:
    -----------
    X : array-like, shape (n_samples, n_features)
        The input data.

    Returns:
    --------
    y_proba : array-like, shape (n_samples, n_classes)
        The predicted class probabilities.

    Example:
    -----------
    Initialize an Extreme Learning Machine (ELM) layer with 1000 neurons

    >>> elm = ELMLayer(number_neurons=1000, activation='mish')

    Create an ELM model using the trained ELM layer

    >>> model = ELMModel(elm)

    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)

◆ save()

ELMModel.ELMModel.save ( self,
file_path )
    Save the model to an HDF5 file.

    Parameters:
    -----------
    file_path : str
        The path to the HDF5 file where the model will be saved.

    Example:
    -----------
    Save the trained model to a file

    >>> model.save("Saved Models/ELM_Model.h5")

◆ to_dict()

ELMModel.ELMModel.to_dict ( self)
    Convert the model to a dictionary of attributes.

    Returns:
    --------
    attributes : dict
        A dictionary containing the attributes of the model.

The documentation for this class was generated from the following file: