dataset = seaborn.load_dataset("iris")
D = dataset.values
X = D[:, :-1]
y = D[:, -1]
X here contains all the features, and y contains the target variable.
model = SVC() ecoc = OutputCodeClassifier(model, code_size=2, random_state=1)
Now, we are initializing the Support Vector Machine Classifier (SVC) using the SVC class. We are then using the binary classifier to initialize the Error Correcting Output Code (ECOC) classifier. Please note that the argument code_size is used to determine the required number of binary classifiers. If the code_size is more than 1, then more number of binary classifiers are required than the number of different classes in the multiclass classification problem. And the argument random_state is used to initialize the pseudo-random number generator that is used for randomization.
scores = cross_val_score(ecoc, X, y, scoring="accuracy", cv=kfold) print(scores.mean())
Now, we are estimating the performance of the model using the cross_val_score() function. 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 core here.
The output of the given program will be like the following:
0.9466666666666667








































0 Comments