estimators

In this module, Standard TwinSVM and Least Squares TwinSVM estimators are defined.

Functions

rbf_kernel(x, y, u) It transforms samples into higher dimension using Gaussian (RBF) kernel.

Classes

BaseTSVM(kernel, rect_kernel, C1, C2, gamma) Base class for TSVM-based estimators
LSTSVM([kernel, rect_kernel, C1, C2, gamma, …]) Least Squares Twin Support Vector Machine (LSTSVM) for binary classification.
TSVM([kernel, rect_kernel, C1, C2, gamma]) Standard Twin Support Vector Machine for binary classification.
class estimators.BaseTSVM(kernel, rect_kernel, C1, C2, gamma)[source]

Bases: sklearn.base.BaseEstimator

Base class for TSVM-based estimators

Parameters:

kernel : str

Type of the kernel function which is either ‘linear’ or ‘RBF’.

rect_kernel : float

Percentage of training samples for Rectangular kernel.

C1 : float

Penalty parameter of first optimization problem.

C2 : float

Penalty parameter of second optimization problem.

gamma : float

Parameter of the RBF kernel function.

Attributes

mat_C_t (array-like, shape = [n_samples, n_samples]) A matrix that contains kernel values.
cls_name (str) Name of the classifier.
w1 (array-like, shape=[n_features]) Weight vector of class +1’s hyperplane.
b1 (float) Bias of class +1’s hyperplane.
w2 (array-like, shape=[n_features]) Weight vector of class -1’s hyperplane.
b2 (float) Bias of class -1’s hyperplane.

Methods

check_clf_params() Checks whether the estimator’s input parameters are valid.
decision_function(X) Computes distance of test samples from both non-parallel hyperplanes
fit(X, y) It fits a TSVM-based estimator.
get_params([deep]) Get parameters for this estimator.
get_params_names() For retrieving the names of hyper-parameters of the TSVM-based estimator.
predict(X) Performs classification on samples in X using the TSVM-based model.
set_params(**params) Set the parameters of this estimator.
check_clf_params()[source]

Checks whether the estimator’s input parameters are valid.

get_params_names()[source]

For retrieving the names of hyper-parameters of the TSVM-based estimator.

Returns:

parameters : list of str, {[‘C1’, ‘C2’], [‘C1’, ‘C2’, ‘gamma’]}

Returns the names of the hyperparameters which are same as the class’ attributes.

fit(X, y)[source]

It fits a TSVM-based estimator. THIS METHOD SHOULD BE IMPLEMENTED IN CHILD CLASS.

Parameters:

X : array-like, shape (n_samples, n_features)

Training feature vectors, where n_samples is the number of samples and n_features is the number of features.

y : array-like, shape(n_samples,)

Target values or class labels.

predict(X)[source]

Performs classification on samples in X using the TSVM-based model.

Parameters:

X : array-like, shape (n_samples, n_features)

Feature vectors of test data.

Returns:

array, shape (n_samples,)

Predicted class lables of test data.

decision_function(X)[source]

Computes distance of test samples from both non-parallel hyperplanes

Parameters:

X : array-like, shape (n_samples, n_features)

Returns:

array-like, shape(n_samples, 2)

distance from both hyperplanes.

class estimators.TSVM(kernel='linear', rect_kernel=1, C1=1, C2=1, gamma=1)[source]

Bases: estimators.BaseTSVM

Standard Twin Support Vector Machine for binary classification. It inherits attributes of BaseTSVM.

Parameters:

kernel : str, optional (default=’linear’)

Type of the kernel function which is either ‘linear’ or ‘RBF’.

rect_kernel : float, optional (default=1.0)

Percentage of training samples for Rectangular kernel.

C1 : float, optional (default=1.0)

Penalty parameter of first optimization problem.

C2 : float, optional (default=1.0)

Penalty parameter of second optimization problem.

gamma : float, optional (default=1.0)

Parameter of the RBF kernel function.

Methods

check_clf_params() Checks whether the estimator’s input parameters are valid.
decision_function(X) Computes distance of test samples from both non-parallel hyperplanes
fit(X_train, y_train) It fits the binary TwinSVM model according to the given training data.
get_params([deep]) Get parameters for this estimator.
get_params_names() For retrieving the names of hyper-parameters of the TSVM-based estimator.
predict(X) Performs classification on samples in X using the TSVM-based model.
set_params(**params) Set the parameters of this estimator.
fit(X_train, y_train)[source]

It fits the binary TwinSVM model according to the given training data.

Parameters:

X_train : array-like, shape (n_samples, n_features)

Training feature vectors, where n_samples is the number of samples and n_features is the number of features.

y_train : array-like, shape(n_samples,)

Target values or class labels.

class estimators.LSTSVM(kernel='linear', rect_kernel=1, C1=1, C2=1, gamma=1, mem_optimize=False)[source]

Bases: estimators.BaseTSVM

Least Squares Twin Support Vector Machine (LSTSVM) for binary classification. It inherits attributes of BaseTSVM.

Parameters:

kernel : str, optional (default=’linear’)

Type of the kernel function which is either ‘linear’ or ‘RBF’.

rect_kernel : float, optional (default=1.0)

Percentage of training samples for Rectangular kernel.

C1 : float, optional (default=1.0)

Penalty parameter of first optimization problem.

C2 : float, optional (default=1.0)

Penalty parameter of second optimization problem.

gamma : float, optional (default=1.0)

Parameter of the RBF kernel function.

mem_optimize : boolean, optional (default=False)

If it’s True, it optimizes the memory consumption siginificantly. However, the memory optimization increases the CPU time.

Methods

check_clf_params() Checks whether the estimator’s input parameters are valid.
decision_function(X) Computes distance of test samples from both non-parallel hyperplanes
fit(X, y) It fits the binary Least Squares TwinSVM model according to the given training data.
get_params([deep]) Get parameters for this estimator.
get_params_names() For retrieving the names of hyper-parameters of the TSVM-based estimator.
predict(X) Performs classification on samples in X using the TSVM-based model.
set_params(**params) Set the parameters of this estimator.
fit(X, y)[source]

It fits the binary Least Squares TwinSVM model according to the given training data.

Parameters:

X : array-like, shape (n_samples, n_features)

Training feature vectors, where n_samples is the number of samples and n_features is the number of features.

y : array-like, shape(n_samples,)

Target values or class labels.

estimators.rbf_kernel(x, y, u)[source]

It transforms samples into higher dimension using Gaussian (RBF) kernel.

Parameters:

x, y : array-like, shape (n_features,)

A feature vector or sample.

u : float

Parameter of the RBF kernel function.

Returns:

float

Value of kernel matrix for feature vector x and y.