Fit data-set using Chebyshev Kernel

[2]:
import orsvm
import pandas as pd
import numpy as np

Load data-set

[3]:
# Fitting a model requires the data-set to be prepared, in order to be a binary classification.
df = pd.read_csv(r'D:\IPM\ORSVM\DataSets\DataSets\Classification\monks-problems\monks1_train.csv')


y_train=df['label'].to_numpy()         # convert y_train to numpy array
df.drop('label', axis=1, inplace=True) # drop the class label
X_train=df.to_numpy()                  # convert x_train to numpy array


# load test-set
df = pd.read_csv(r'D:\IPM\ORSVM\DataSets\DataSets\Classification\monks-problems\monks1_test.csv')

y_test=df['label'].to_numpy()
df.drop('label', axis=1, inplace=True)
X_test=df.to_numpy()

Initiate kernel

[4]:
# Create an object from Model class of ORSVM
obj=orsvm.Model(kernel="Chebyshev",order=3,T=0.5,form='r')

Fit the model and Capture paramaters

[6]:
# fit the model and Capture parameters
Weights, SupportVectors, Bias, KernelInstance = obj.ModelFit(X_train,y_train)
2022-10-22 22:34:32,328:INFO:** ORSVM kernel: chebyshev
2022-10-22 22:34:32,329:INFO:** Order: 3
2022-10-22 22:34:32,329:INFO:** Fractional mode, transition : 0.5
2022-10-22 22:34:32,789:INFO:** Average method for support vector determination selected!
2022-10-22 22:34:32,790:INFO:** support vector threshold: 10^-4
2022-10-22 22:34:32,831:INFO:Kenrel matrix is convex
2022-10-22 22:34:32,831:INFO:** solution status: optimal

Inspect model’s accuracy

[7]:
# Model Prediction function
obj.ModelPredict(X_test,y_test,Bias,KernelInstance)
2022-10-22 22:34:55,494:INFO:** Accuracy score: 0.9120370370370371
2022-10-22 22:34:55,499:INFO:** Classification Report:
               precision    recall  f1-score   support

          -1       0.89      0.94      0.91       216
           1       0.93      0.89      0.91       216

    accuracy                           0.91       432
   macro avg       0.91      0.91      0.91       432
weighted avg       0.91      0.91      0.91       432

2022-10-22 22:34:55,506:INFO:** Confusion Matrix:
 [[202  14]
 [ 24 192]]
[7]:
0.9120370370370371