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. n_splits here indicates the number of splits. And shuffle=True indicates that we are shuffling the data before splitting. The random_state argument is used to initialize the pseudo-random number generator that is used for randomization.
classifier = SVC() ovo = OneVsOneClassifier(classifier)
Now, we are initializing the binary classifier Support Vector Machine Classifier. Then, we are using the binary classifier to initialize the One-Vs-One classifier.
scores = cross_val_score(ovo, X, y, scoring="accuracy", cv=kfold)
print("Accuracy: ", scores.mean())
Now, we are estimating the performance of the model using cross_val_score(). We are using the accuracy score here (What is the accuracy score in machine learning?). We will get an accuracy score for each iteration of the k-fold cross-validation. We are printing the average accuracy score.
The output of the given program will be like the following:
Accuracy: 0.96








































0 Comments