autoqild.classifiers.multi_layer_perceptronΒΆ
A customizable feedforward neural network implemented using Keras for more complex classification tasks.
Classes
|
MultiLayerPerceptron class for building and training a feedforward neural network using Keras. |
- class autoqild.classifiers.multi_layer_perceptron.MultiLayerPerceptron(n_features, n_classes, n_hidden=10, n_units=100, batch_normalization=True, activation='relu', loss_function='categorical_crossentropy', metrics=['accuracy'], optimizer_str='adam', reg_strength=0.0001, kernel_initializer='lecun_normal', learning_rate=0.001, early_stopping=False, model_save_path='', random_state=None, **kwargs)[source]ΒΆ
Bases:
BaseEstimator,ClassifierMixinMultiLayerPerceptron class for building and training a feedforward neural network using Keras.
- Parameters:
n_features (int) β Number of features or dimensionality of the inputs.
n_classes (int) β Number of classes in the classification data samples.
n_hidden (int, optional, default=10) β Number of hidden layers.
n_units (int, optional, default=100) β Number of units per hidden layer.
batch_normalization (bool, optional, default=True) β Whether to use batch normalization.
activation (str, optional, default="relu") β Activation function to use in the hidden layers.
loss_function (str, optional, default="categorical_crossentropy") β Loss function to use for training.
metrics (list of str, optional, default=["accuracy"]) β List of metrics to be evaluated by the model during training and testing.
optimizer_str ({"adam", "sgd", ...}, default="adam") β Optimizer to use for training. Must be one of the optimizers available in Keras.
reg_strength (float, optional, default=1e-4) β Regularization strength for the L2 regularizer.
kernel_initializer (str, optional, default="lecun_normal") β Initializer for the kernel weights matrix.
learning_rate (float, optional, default=0.001) β Learning rate for the optimizer.
early_stopping (bool, optional, default=False) β Whether to use early stopping during training.
model_save_path (str, optional, default="") β Path to save the trained model.
random_state (int or None, optional, default=None) β Random state for reproducibility.
**kwargs (dict, optional) β Additional keyword arguments.
- modelΒΆ
The compiled Keras model for training and prediction in form of labels.
- Type:
keras.Model or None
- scoring_modelΒΆ
The compiled Keras model for predicting real-valued scores.
- Type:
keras.Model or None
- loggerΒΆ
Logger object used for logging messages and errors.
- Type:
logging.Logger
- Private Methods
- ---------------
- _construct_layers(**kwargs)[source]ΒΆ
Construct the input, hidden, and output layers for the MLP model.
- decision_function(X, verbose=0)[source]ΒΆ
Compute the real-valued scores for each class for the input samples.
- Parameters:
X (array-like of shape (n_samples, n_features)) β Feature matrix.
verbose (int, optional, default=0) β Verbosity mode.
- Returns:
decision β Decision function values.
- Return type:
array-like of shape (n_samples,)
- fit(X, y, epochs=50, batch_size=32, callbacks=None, validation_split=0.1, verbose=1, **kwd)[source]ΒΆ
Fit the MLP model to the training data.
- Parameters:
X (array-like of shape (n_samples, n_features)) β Feature matrix.
y (array-like of shape (n_samples,)) β Target vector.
epochs (int, optional, default=50) β Number of training epochs.
batch_size (int, optional, default=32) β Number of samples per gradient update.
callbacks (list of keras.callbacks.Callback, optional) β List of callback instances to apply during training.
validation_split (float, optional, default=0.1) β Fraction of the training data to be used as validation data.
verbose (int, optional, default=1) β Verbosity mode.
**kwd (dict, optional) β Additional keyword arguments.
- Returns:
self β Fitted estimator.
- Return type:
- get_params(deep=True)[source]ΒΆ
Get parameters for this estimator.
- Parameters:
deep (bool, default=True) β If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
params β Parameter names mapped to their values.
- Return type:
dict
- predict(X, verbose=0)[source]ΒΆ
Predict class labels for the input samples with maximum class probability.
- Parameters:
X (array-like of shape (n_samples, n_features)) β Feature matrix.
verbose (int, optional, default=0) β Verbosity mode.
- Returns:
y_pred β Predicted class labels.
- Return type:
array-like of shape (n_samples,)
- predict_proba(X, verbose=0)[source]ΒΆ
Predict class probabilities for the input samples.
- Parameters:
X (array-like of shape (n_samples, n_features)) β Feature matrix.
verbose (int, optional, default=0) β Verbosity mode.
- Returns:
p_pred β Predicted class probabilities.
- Return type:
array-like of shape (n_samples, n_classes)
- reshape_inputs(y)[source]ΒΆ
Reshape target variable to categorical format if necessary.
- Parameters:
y (array-like of shape (n_samples,)) β Target vector.
- Returns:
y β Reshaped target vector.
- Return type:
array-like of shape (n_samples, n_classes)
- score(X, y, sample_weight=None, verbose=0)[source]ΒΆ
Compute the balanced accuracy score for the input samples.
- Parameters:
X (array-like of shape (n_samples, n_features)) β Feature matrix.
y (array-like of shape (n_samples,)) β True labels.
sample_weight (array-like of shape (n_samples,), optional) β Sample weights.
verbose (int, optional, default=0) β Verbosity mode.
- Returns:
acc β Balanced accuracy score.
- Return type:
float
- set_params(**parameters)[source]ΒΆ
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as :class:β~sklearn.pipeline.Pipelineβ). The latter have parameters of the form ββ<component>__<parameter>ββ so that itβs possible to update each component of a nested object.
- Parameters:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance