My dataset is divided into two groups. one is for training (with shape of [3850,5]) and the other is for testing (with shape of [1050,5]). I used this code for defining wave kernel (you can find it in this paper) function:
import numpy as np from scipy.spatial.distance import cdist from sklearn import svm import pandas as pd def wave_kernel(mat_v, mat_u): deg = 80 teta = np.deg2rad(deg) v = cdist(mat_v, mat_u, 'euclidean') return (teta/v) * np.sin(v/teta)
and use this code for predicting labels (and see how well kernel works):
data = pd.read_csv('data.csv') features = ['feat1', 'feat2', 'feat3', 'feat4', 'feat5'] X_train = data[features].iloc[:3850].values X_test = data[features].iloc[3850:].values y_train = data['label'].iloc[:3850].values y_test = data['label'].iloc[3850:].values def RE(y_true, y_pred): # Calculating Relative error return np.mean(np.abs((y_true - y_pred) / y_true)) svr = svm.SVR(kernel=wave_kernel) y_pred = svr.fit(X_train, y_train).predict(X_test) a = RE(y_test, y_pred) print(a)
After I run the code, the code encounters a Run Time Error which says:
RuntimeWarning: divide by zero encountered in true_divide
and another one following first one
RuntimeWarning: invalid value encountered in multiply
I really don't know what that error is for because it does not explicitly mention the line.
I have used the kernel function separately with matrices to see if the error happens inside the function but that worked fine.
I can't figure out what to do. please help me out!