Fit data-set using Jacobi 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
[ ]:
# Create an object from Model class of ORSVM
obj=orsvm.Model(kernel="Jacobi",order=3,KernelParam1=-0.8,KernelParam2=0.2,T=0.8,noise=0.1)
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:45:00,827:INFO:** ORSVM kernel: jacobi
2022-10-22 22:45:00,828:INFO:** Order: 3
2022-10-22 22:45:00,829:INFO:** Fractional mode, transition : 0.8
2022-10-22 22:45:02,325:INFO:** Average method for support vector determination selected!
2022-10-22 22:45:02,326:INFO:** support vector threshold: 10^-3
2022-10-22 22:45:02,349:INFO:Kenrel matrix is convex
2022-10-22 22:45:02,350:INFO:** solution status: optimal
Inspect model’s accuracy
[6]:
# Model Prediction function
obj.ModelPredict(X_test,y_test,Bias,KernelInstance)
2022-10-22 22:45:27,992:INFO:** Accuracy score: 0.8495370370370371
2022-10-22 22:45:27,996:INFO:** Classification Report:
precision recall f1-score support
-1 0.83 0.88 0.85 216
1 0.87 0.82 0.84 216
accuracy 0.85 432
macro avg 0.85 0.85 0.85 432
weighted avg 0.85 0.85 0.85 432
2022-10-22 22:45:27,999:INFO:** Confusion Matrix:
[[190 26]
[ 39 177]]
[6]:
0.8495370370370371