Fit data-set using Gegenbauer 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
[5]:
# Create an object from Model class of ORSVM
obj=orsvm.Model(kernel="Gegenbauer",order=4,KernelParam1=0.5,T=0.3)
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:38:44,690:INFO:** ORSVM kernel: gegenbauer
2022-10-22 22:38:44,691:INFO:** Order: 4
2022-10-22 22:38:44,692:INFO:** Fractional mode, transition : 0.3
2022-10-22 22:38:45,301:INFO:** Average method for support vector determination selected!
2022-10-22 22:38:45,302:INFO:** support vector threshold: 10^-6
2022-10-22 22:38:45,323:INFO:Kenrel matrix is convex
2022-10-22 22:38:45,323:INFO:** solution status: optimal
Inspect model’s accuracy
[7]:
# Model Prediction function
obj.ModelPredict(X_test,y_test,Bias,KernelInstance)
2022-10-22 22:39:02,515:INFO:** Accuracy score: 0.9328703703703703
2022-10-22 22:39:02,520: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:39:02,523:INFO:** Confusion Matrix:
[[197 19]
[ 10 206]]
[7]:
0.9328703703703703