What is a One-Vs-Rest (OVR) classifier?
The Support Vector Machine Classifier (SVC) is a binary classifier. It can solve a classification problem in which the target variable can take any of two different values. But, we can use SVC along with a One-Vs-Rest (OVR) classifier or a One-Vs-One (OVO) classifier to solve a multiclass classification problem.
The One-Vs-Rest (OVR) classifier uses the One-Vs-Rest strategy to break a multiclass classification problem into n number of binary classification problems where n is the number of different values the target variable can take.
For example, if the target variable can take three different values A, B, and C, then an OVR classifier breaks the multiclass classification problem into the following binary classification problems.
Problem 1: A vs. (B, C) Problem 2: B vs. (A, C) Problem 3: C vs. (A, B)
Now, the OVR classifier can use a binary classifier to solve these binary classification problems and then, use the results to predict the outcome of the target variable. (One-vs-Rest vs. One-vs-One Multiclass Classification)
One-Vs-Rest (OVR) Classifier with Support Vector Machine Classifier (SVC) using sklearn in Python
We can use the following Python code to solve a multiclass classification problem using a One-Vs-Rest Classifier with an SVC.
import seaborn from sklearn.model_selection import KFold from sklearn.model_selection import cross_val_score from sklearn.multiclass import OneVsRestClassifier from sklearn.svm import SVC dataset = seaborn.load_dataset("iris") D = dataset.values X = D[:, :-1] y = D[:, -1] kfold = KFold(n_splits=10, shuffle=True, random_state=1) classifier = SVC() ovr = OneVsRestClassifier(classifier) scores = cross_val_score(ovr, X, y, scoring="accuracy", cv=kfold) print("Accuracy: ", scores.mean())
Here, we are first reading the iris dataset and splitting the columns of the dataset into features and the target variable. The first four columns of the dataset contain the features sepal length, sepal width, petal length, and petal width. The last column of the dataset contains the target variable species…
0 Comments