| |
- sega_learn.svm.baseSVM.BaseSVM(builtins.object)
-
- OneClassSVM
class OneClassSVM(sega_learn.svm.baseSVM.BaseSVM) |
|
OneClassSVM(C=1.0, tol=0.0001, max_iter=1000, learning_rate=0.01, kernel='linear', degree=3, gamma='scale', coef0=0.0)
OneClassSVM is a custom implementation of a One-Class Support Vector Machine (SVM) for anomaly detection using gradient descent.
It inherits from the BaseSVM class and supports various kernel functions.
Attributes:
support_vectors_ (array-like of shape (n_support_vectors, n_features)):
The support vectors identified during training.
support_vector_alphas_ (array-like of shape (n_support_vectors,)):
The Lagrange multipliers (alpha) corresponding to the support vectors.
b (float):
The bias term (rho) computed during training.
Methods:
__init__(C=1.0, tol=1e-4, max_iter=1000, learning_rate=0.01, kernel="linear",
degree=3, gamma="scale", coef0=0.0):
Initialize the OneClassSVM with hyperparameters.
_fit(X, y=None):
Fit the OneClassSVM model using gradient descent for anomaly detection.
decision_function(X):
Compute the decision function values for the input samples.
predict(X):
Predict whether the input samples are inliers (1) or outliers (-1).
score(X, y):
Compute the mean accuracy of predictions compared to true labels.
__sklearn_is_fitted__():
Check if the model has been fitted. For compatibility with sklearn. |
|
- Method resolution order:
- OneClassSVM
- sega_learn.svm.baseSVM.BaseSVM
- builtins.object
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)
- Initialize the OneClassSVM with 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 (default is 1000).
learning_rate: (float) - Learning rate for gradient descent (default is 0.01).
kernel: (str) - Kernel type ("linear", "poly", "rbf", "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 kernel function (default is 0.0).
- __sklearn_is_fitted__(self)
- Check if the model has been fitted. For compatibility with sklearn.
Returns:
fitted: (bool) - True if the model has been fitted, otherwise False.
- decision_function(self, X)
- Compute the decision function values for the input samples.
- predict(self, X)
- Predict whether the input samples are inliers (1) or outliers (-1).
- score(self, X, y)
- Compute the mean accuracy of predictions.
Args:
X: (array-like of shape (n_samples, n_features)) - Test samples.
y: (array-like of shape (n_samples,)) - True labels (+1 for inliers, -1 for outliers).
Returns:
score: (float) - Mean accuracy of predictions.
Methods inherited from sega_learn.svm.baseSVM.BaseSVM:
- 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.
- 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 inherited from sega_learn.svm.baseSVM.BaseSVM:
- __dict__
- dictionary for instance variables
- __weakref__
- list of weak references to the object
| |