dataset = seaborn.load_dataset("iris") D = dataset.values X = D[:, :-1] y = D[:, -1]
So, X here contains all the features and y contains the target variable.
kfold = KFold(n_splits=10, shuffle=True, random_state=1)
Now, we are initializing the k-fold cross-validation. We are using 10 number of splits. We are shuffling the data before splitting. And the random_state argument is used to initialize the pseudo-random number generator that is used for randomization.
classifier = SVC() ovr = OneVsRestClassifier(classifier)
Now, we are initializing the binary classifier using the SVC class and using the binary classifier to initialize the One-Vs-Rest (OVR) classifier.
scores = cross_val_score(ovr, X, y, scoring="accuracy", cv=kfold) print("Accuracy: ", scores.mean())
Now, we are using the cross_val_score() function to estimate the performance of the model. We are using an accuracy score here (What is the accuracy score in machine learning?) Please note that we will get an accuracy score for each iteration of the k-fold cross-validation. We are printing the average accuracy score here.
The output of the given program will be like the following:
Accuracy: 0.9400000000000001






0 Comments