Fit data-set using Legendre 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="Legendre",order=4,T=0.3)

Fit the model and Capture paramaters

[5]:
# fit the model and Capture parameters
Weights, SupportVectors, Bias, KernelInstance = obj.ModelFit(X_train,y_train)
2022-10-22 22:47:45,130:INFO:** ORSVM kernel: legendre
2022-10-22 22:47:45,132:INFO:** Order: 4
2022-10-22 22:47:45,133:INFO:** Fractional mode, transition : 0.3
2022-10-22 22:47:45,709:INFO:** Average method for support vector determination selected!
2022-10-22 22:47:45,710:INFO:** support vector threshold: 10^-6
2022-10-22 22:47:45,730:INFO:Kenrel matrix is convex
2022-10-22 22:47:45,731:INFO:** solution status: optimal

Inspect model’s accuracy

[6]:
# Model Prediction function
obj.ModelPredict(X_test,y_test,Bias,KernelInstance)
2022-10-22 22:48:03,590:INFO:** Accuracy score: 0.9328703703703703
2022-10-22 22:48:03,594:INFO:** Classification Report:
               precision    recall  f1-score   support

          -1       0.95      0.91      0.93       216
           1       0.92      0.95      0.93       216

    accuracy                           0.93       432
   macro avg       0.93      0.93      0.93       432
weighted avg       0.93      0.93      0.93       432

2022-10-22 22:48:03,597:INFO:** Confusion Matrix:
 [[197  19]
 [ 10 206]]
[6]:
0.9328703703703703