predicted. The four features are sepal length, sepal width, petal length, and petal width. And the last column of the dataset contains the target variable species.
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. And 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 = LogisticRegression(solver="liblinear") ovr = OneVsRestClassifier(classifier)
Here, we are first initializing the binary classifier using the LogisticRegression class. Then, we are 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?) 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.9466666666666667








































0 Comments