twinsvm

Classes and functios are defined for training and testing TwinSVM classifier.

TwinSVM classifier generates two non-parallel hyperplanes. For more info, refer to the original papar. Khemchandani, R., & Chandra, S. (2007). Twin support vector machines for pattern classification. IEEE Transactions on pattern analysis and machine intelligence, 29(5), 905-910.

Motivated by the following paper, the multi-class TSVM is developed. Tomar, D., & Agarwal, S. (2015). A comparison on multi-class classification methods based on least squares twin support vector machine. Knowledge-Based Systems, 81, 131-147.

Functions

rbf_kernel(x, y, u) It transforms samples into higher dimension Input: x,y: Samples u: Gamma parameter Output: Samples with higher dimension

Classes

HyperPlane()
MCTSVM([kernel, C, gamma]) Multi Class Twin Support Vector Machine One-vs-All Scheme
OVO_TSVM([kernel, C1, C2, gamma]) Multi Class Twin Support Vector Machine One-vs-One Scheme This classifier is scikit-learn compatible, which means scikit-learn features such as cross_val_score and GridSearchCV can be used for OVO_TSVM
TSVM([kernel, rect_kernel, C1, C2, gamma])
class twinsvm.TSVM(kernel='linear', rect_kernel=1, C1=1, C2=1, gamma=1)[source]

Bases: sklearn.base.BaseEstimator

get_params_names()[source]

It returns the names of hyper-parameters of this classifier.

fit(X_train, y_train)[source]

It trains TwinSVM classfier on given data Input:

X_train: Training samples y_train: Samples’ category

output:

w1, w2: Coordinates of two non-parallel hyperplanes b1, b2: Biases
predict(X_test)[source]

Predictes class of test samples Input:

X_test: Test samples
twinsvm.rbf_kernel(x, y, u)[source]

It transforms samples into higher dimension Input:

x,y: Samples u: Gamma parameter
Output:
Samples with higher dimension
class twinsvm.MCTSVM(kernel='linear', C=1, gamma=1)[source]

Bases: sklearn.base.BaseEstimator

Multi Class Twin Support Vector Machine One-vs-All Scheme

get_params_names()[source]

It returns the names of hyper-parameters of this classifier.

fit(X_train, y_train)[source]
Input:
X_train: Training samples y_train: Lables of training samples
predict(X_test)[source]
Predictes class of test samples
Input:
X_test: Test samples
class twinsvm.OVO_TSVM(kernel='linear', C1=1, C2=1, gamma=1)[source]

Bases: sklearn.base.BaseEstimator, sklearn.base.ClassifierMixin

Multi Class Twin Support Vector Machine One-vs-One Scheme This classifier is scikit-learn compatible, which means scikit-learn features such as cross_val_score and GridSearchCV can be used for OVO_TSVM

get_params_names()[source]

It returns the names of hyper-parameters of this classifier.

fit(X, y)[source]

Given training set, it creates a SVM model

Parameters:
X_train: Training samples, (n_samples, n_features) y_train: Target values, (n_samples, )
predict(X)[source]

Predicits lables of test samples

Parameters:
X_test: test samples, (n_samples, n_features)
Returns:
y_pred: array, (n_samples,)