sega_learn.svm.baseSVM

 
Modules
       
numpy

 
Classes
       
builtins.object
BaseSVM

 
class BaseSVM(builtins.object)
    BaseSVM(C=1.0, tol=0.0001, max_iter=1000, learning_rate=0.01, kernel='linear', degree=3, gamma='scale', coef0=0.0, regression=False)
 
BaseSVM: A base class for Support Vector Machines (SVM) with kernel support.
 
This class provides the foundation for implementing SVM models with various kernels
and supports both classification and regression tasks.
 
Attributes:
    C (float): Regularization parameter. Default is 1.0.
    tol (float): Tolerance for stopping criteria. Default is 1e-4.
    max_iter (int): Maximum number of iterations for optimization. Default is 1000.
    learning_rate (float): Step size for optimization. Default is 0.01.
    kernel (str): Kernel type ('linear', 'poly', 'rbf', or 'sigmoid'). Default is 'linear'.
    degree (int): Degree for polynomial kernel. Default is 3.
    gamma (str or float): Kernel coefficient ('scale', 'auto', or float). Default is 'scale'.
    coef0 (float): Independent term in poly and sigmoid kernels. Default is 0.0.
    regression (bool): Whether to use regression (SVR) or classification (SVC). Default is False.
    w (ndarray): Weight vector for linear kernel.
    b (float): Bias term.
    support_vectors_ (ndarray): Support vectors identified during training.
    support_vector_labels_ (ndarray): Labels of the support vectors.
    support_vector_alphas_ (ndarray): Lagrange multipliers for the support vectors.
 
Methods:
    __init__(self, C=1.0, tol=1e-4, max_iter=1000, learning_rate=0.01, kernel='linear', degree=3, gamma='scale', coef0=0.0, regression=False):
        Initializes the BaseSVM instance with specified hyperparameters.
    fit(self, X, y=None):
        Fits the SVM model to the training data.
    _fit(self, X, y):
        Abstract method to be implemented by subclasses for training.
    _compute_kernel(self, X1, X2):
        Computes the kernel function between two input matrices.
    decision_function(self, X):
        Computes the decision function for input samples.
    predict(self, X):
        Predicts class labels for input samples.
    score(self, X, y):
        Computes the mean accuracy of the model on the given test data.
    get_params(self, deep=True):
        Retrieves the hyperparameters of the model.
    set_params(self, **parameters):
        Sets the hyperparameters of the model.
    __sklearn_is_fitted__(self):
        Checks if the model has been fitted (for sklearn compatibility).
 
  Methods defined here:
__init__(self, C=1.0, tol=0.0001, max_iter=1000, learning_rate=0.01, kernel='linear', degree=3, gamma='scale', coef0=0.0, regression=False)
Initializes the BaseSVM instance with specified hyperparameters.
 
Args:
    C: (float) - Regularization parameter. Default is 1.0.
    tol: (float) - Tolerance for stopping criteria. Default is 1e-4.
    max_iter: (int) - Maximum number of iterations for optimization. Default is 1000.
    learning_rate: (float) - Step size for optimization. Default is 0.01.
    kernel: (str) - Kernel type ('linear', 'poly', 'rbf', or 'sigmoid'). Default is 'linear'.
    degree: (int) - Degree for polynomial kernel. Default is 3.
    gamma: (str or float) - Kernel coefficient ('scale', 'auto', or float). Default is 'scale'.
    coef0: (float) - Independent term in poly and sigmoid kernels. Default is 0.0.
    regression: (bool) - Whether to use regression (SVR) or classification (SVC). Default is False.
__sklearn_is_fitted__(self)
Checks if the model has been fitted (for sklearn compatibility).
 
Returns:
    fitted: (bool) - True if the model has been fitted, otherwise False.
decision_function(self, X)
Computes the decision function for input samples.
 
Args:
    X: (array-like of shape (n_samples, n_features)) - Input samples.
 
Returns:
    decision_values: (ndarray of shape (n_samples,)) - Decision function values.
fit(self, X, y=None)
Fits the SVM model to the training data.
 
Args:
    X: (array-like of shape (n_samples, n_features)) - Training vectors.
    y: (array-like of shape (n_samples,)) - Target values. Default is None.
 
Returns:
    self: (BaseSVM) - The fitted instance.
get_params(self, deep=True)
Retrieves the hyperparameters of the model.
 
Args:
    deep: (bool) - If True, returns parameters of subobjects as well. Default is True.
 
Returns:
    params: (dict) - Dictionary of hyperparameter names and values.
predict(self, X)
Predicts class labels for input samples.
 
Args:
    X: (array-like of shape (n_samples, n_features)) - Input samples.
 
Returns:
    predicted_labels: (ndarray of shape (n_samples,)) - Predicted class labels.
score(self, X, y)
Computes the mean accuracy of the model on the given test data.
 
Args:
    X: (array-like of shape (n_samples, n_features)) - Test samples.
    y: (array-like of shape (n_samples,)) - True class labels.
 
Returns:
    score: (float) - Mean accuracy of predictions.
set_params(self, **parameters)
Sets the hyperparameters of the model.
 
Args:
    **parameters: (dict) - Hyperparameter names and values.
 
Returns:
    self: (BaseSVM) - The updated estimator instance.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object