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

Public Member Functions

 __init__ (self, KELMLayer kelm, classification=True)
 
 fit (self, X, y)
 
 predict (self, X)
 
 to_dict (self)
 
 load (cls, str file_path)
 
 save (self, file_path)
 
 predict_proba (self, X)
 

Public Attributes

 classes_
 
 classification
 
 kelm
 

Detailed Description

    Kernel Extreme Learning Machine (KELM) Model.

    This class implements a Kernel Extreme Learning Machine model for classification or regression tasks.

    Parameters:
    -----------
        kelm (KELMLayer): Instance of a Kernel ELM model.
        classification (bool, optional): Whether the task is classification or regression.
            Defaults to True.

    Attributes:
    -----------
        classes_ (array-like): Unique class labels.
        classification (bool): Indicates whether the task is classification or regression.
        kelm (KELMLayer): Instance of a Kernel ELM model.

    Methods:
    -----------
        fit(X, y): Fit the KELM model to training data.
        predict(X): Predict class labels or regression values for input data.
        to_dict(): Convert the model to a dictionary of attributes.
        load(file_path): Deserialize an instance from a file.
        save(file_path): Serialize the current instance and save it to a HDF5 file.
        predict_proba(X): Predict class labels or regression values for input data.

    Examples:
    -----------
    Initialize a Kernel (it can be instanced as Kernel class and its subclasses like CombinedProductKernel)

    >>> kernel = CombinedProductKernel([Kernel("rational_quadratic"), Kernel("exponential")])

    Initialize a Kernel Extreme Learning Machine (KELM) layer

    >>> layer = KELMLayer(kernel, 'mish')

    Initialize a Kernel Extreme Learning Machine (KELM) model

    >>> model = KELMModel(layer)

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

    Load the saved model from the file

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

    Evaluate the accuracy of the model on the training data

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

Member Function Documentation

◆ fit()

KELMModel.KELMModel.fit ( self,
X,
y )
    Fit the KELM model to training data.

    Args:
    -----------
        X (array-like): Training input samples.
        y (array-like): Target values.

    Examples:
    -----------
    Initialize a Kernel (it can be instanced as Kernel class and its subclasses like CombinedProductKernel)

    >>> kernel = CombinedProductKernel([Kernel("rational_quadratic"), Kernel("exponential")])

    Initialize a Kernel Extreme Learning Machine (KELM) layer

    >>> layer = KELMLayer(kernel, 'mish')

    Initialize a Kernel Extreme Learning Machine (KELM) model

    >>> model = KELMModel(layer)

    Fit the ELM model to the entire dataset

    >>> model.fit(X, y)

◆ load()

KELMModel.KELMModel.load ( cls,
str file_path )
Deserialize an instance from a file.

Parameters:
- file_path (str): The file path from which to load the serialized instance.

Returns:
ELMLayer: An instance of the ELMLayer class loaded from the file.

◆ predict()

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

    Args:
    -----------
        X (array-like): Input samples.

    Returns:
    -----------
        array-like: Predicted class labels or regression values.

    Examples:
    -----------
    Initialize a Kernel (it can be instanced as Kernel class and its subclasses like CombinedProductKernel)

    >>> kernel = CombinedProductKernel([Kernel("rational_quadratic"), Kernel("exponential")])

    Initialize a Kernel Extreme Learning Machine (KELM) layer

    >>> layer = KELMLayer(kernel, 'mish')

    Initialize a Kernel Extreme Learning Machine (KELM) model

    >>> model = KELMModel(layer)

    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()

KELMModel.KELMModel.predict_proba ( self,
X )
    Predict class labels or regression values for input data.

    Args:
    -----------
        X (array-like): Input samples.

    Returns:
    -----------
        array-like: Predicted class labels or regression values.

    Examples:
    -----------
    Initialize a Kernel (it can be instanced as Kernel class and its subclasses like CombinedProductKernel)

    >>> kernel = CombinedProductKernel([Kernel("rational_quadratic"), Kernel("exponential")])

    Initialize a Kernel Extreme Learning Machine (KELM) layer

    >>> layer = KELMLayer(kernel, 'mish')

    Initialize a Kernel Extreme Learning Machine (KELM) model

    >>> model = KELMModel(layer)

    Fit the ELM model to the entire dataset

    >>> model.fit(X, y)

    Evaluate the prediction proba of the model on the training data

    >>> pred_proba = model.predict_proba(X)

◆ save()

KELMModel.KELMModel.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

◆ to_dict()

KELMModel.KELMModel.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: