Explore Courses Blog Tutorials Interview Questions
+2 votes
in Machine Learning by (4.2k points)

I need a somehow descriptive example showing how to do a 10-fold SVM classification on a two class set of data. there is just one example in the MATLAB documentation but it is not with 10-fold. Can someone help me?

1 Answer

+2 votes
by (6.8k points)
edited by

10-fold cross-validation is the most used classification algorithm for predicting the test error for given datasets. It randomly divides the training set into 10 disjoint subsets. Each subset has the roughly equal size and roughly the same class proportions as in the training set. Undergoing a course regarding SVM Algorithms will give you an insight. Remove one set, train the classification model using the other nine subsets, and use the trained model to classify the removed subset. You could repeat this by removing each of the ten subsets one at a time.

import numpy as np

from sklearn.model_selection import KFold

X = np.array([[1, 2], [3, 4], [1, 2], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 21]])

y = np.array([1, 2, 3, 4, 5,6, 7,8 ,9,10,11 ,12])

kf = KFold(n_splits=10)



for train_index, test_index in kf.split(X):

    print("TRAIN:", train_index, "TEST:", test_index)

X_train, X_test = X[train_index], X[test_index]

y_train, y_test = y[train_index], y[test_index]


Related questions

Browse Categories