I'm trying to run a loop that finds the best C (regularization parameter),
for C in range(1, 10):
clf = SVM(Kernel.linear(), C)
clf.fit(X['train'], y['train'].astype('double'))
print("C = ", C)
y_hat = clf.predict(X['train'])
print("Acc on train: ", np.mean(y_hat == y['train']))
y_hat = clf.predict(X['val'])
print("Acc on val: ", np.mean(y_hat == y['val']))
however this is the error I am running into:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_23924\635205938.py in <module>
3 clf.fit(X['train'], y['train'].astype('double'))
4 print("C = ", C)
----> 5 y_hat = clf.predict(X['train'])
6 print("Acc on train: ", np.mean(y_hat == y['train']))
7 y_hat = clf.predict(X['val'])
~\AppData\Local\Temp\ipykernel_23924\270836144.py in predict(self, X)
51
52 for i in range(0, N):
---> 53 result[i] = np.sum(self._weights[i] * self._support_vector_labels[i] * self._kernel(self._support_vectors[i], X[i])) + self._bias
54
55 return np.sign(result)
IndexError: index 1268 is out of bounds for axis 0 with size 1268
I tested out the code on a sample data set where X was 10x2 and it worked fine. This dataset is X:2775x1464, and y is 2775.