dataset = seaborn.load_dataset("iris")
D = dataset.values
X = D[:, :-1]
y = D[:, -1]
Now, we are initializing the logistic regression classifier using the LogisticRegression class.
model = LogisticRegression() ecoc = OutputCodeClassifier(model, code_size=2, random_state=1)
We are also initializing the Error Correcting Output Code (ECOC) classifiers using the OutputCodeClassifier class. Please note that the argument code_size is used to determine the required number of binary classsifiers. 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.
kfold = KFold(n_splits=10, shuffle=True, random_state=1)
Now, we are initializing the k-fold cross-validation with 10 splits. The argument shuffle=True indicates that 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.
scores = cross_val_score(ecoc, X, y, scoring="accuracy", cv=kfold) print(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:
0.7








































0 Comments