Link Search Menu Expand Document

min2net.model.SVM

View source on GitHub

Table of contents

  1. min2net.model.SVM
    1. SVM class
    2. Fit method
    3. Predict method
    4. Example

SVM class

Configures the model for training. This method was implemented based on sklearn.svm.SVC using PredefinedSplit to predefined split cross-validation and GridSearchCV to tune the model.

min2net.model.SVM()

Arguments:

ArgumentsDescriptionDefault
tuned_parameterslist of dictionaries with parameters names (str) as keys and lists of parameter settings for GridSearchCV[{‘kernel’: [‘rbf’],
‘gamma’: [1e-2, 1e-3],
‘C’: [0.001, 0.01, 0.1, 1, 10, 100, 1000]},
{‘kernel’: [‘sigmoid’],
‘gamma’: [1e-2, 1e-3],
‘C’: [0.001, 0.01, 0.1, 1, 10, 100, 1000]},
{‘kernel’: [‘linear’],
‘gamma’: [1e-2, 1e-3],
‘C’:[0.001, 0.01, 0.1, 1, 10, 100, 1000]}]
log_pathstr path to save model‘logs’
model_namestr prefix to save model‘SVM’
**kwargsKeyword argument to pass into the function for replacing the variables of the model such as seed and f1_average-

Fit method

Fit the SVM model according to the given training and validation data. The model with an optimal parameter set will save at 'log_path'.

SVM.fit(X_train, 
        y_train, 
        X_val, 
        y_val)

Arguments:

ArgumentsDescription
X_trainndarray Training EEG signals. shape (#trial, #features)
y_trainndarray Label of training set. shape (#trial)
X_valndarray Validation EEG signals. shape (#trial, #features)
y_valndarray Label of validation set. shape (#trial)

Predict method

Generates output predictions and classification report on samples in X_test.

SVM.predict(X_test, 
            y_test)
ArgumentsDescription
X_testndarray Testing EEG signals. shape (#trial, #features)
y_testndarray Label of test set. shape (#trial)

Returns:

  • Y: dictionary of {y_true, y_pred}
  • evaluation: dictionary of {accuracy, f1_score}

Example

from min2net.model import SVM
import numpy as np

model = SVM()
model.fit(X_train, y_train, X_val, y_val)

Y, evaluation = model.predict(X_test, y_test)