What is the One-vs-Rest (OVR) classifier?
A logistic regression classifier is a binary classifier. So, we cannot use this classifier as it is to solve a multiclass classification problem. As we know, in a binary classification problem, the target categorical variable can take two different values. And, in a multiclass classification problem, the target categorical variable can take more than two different values.
We can use a One-Vs-Rest (OVR) classifier with a logistic regression classifier to solve a multiclass classification problem. Let’s say the target variable of a multiclass classification problem can take three different values A, B, and C. An OVR classifier, in that case, will break the multiclass classification problem into the following three binary classification problems.
Problem 1: A vs. (B, C) Problem 2: B vs. (A, C) Problem 3: C vs. (A, B)
And then, it will solve the binary classification problems using a binary classifier. After that, the OVR classifier will 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 Logistic Regression using sklearn in Python
We can use the following Python code to solve a multiclass classification problem using One-Vs-Rest (OVR) classifier with logistic regression.
import seaborn from sklearn.model_selection import KFold from sklearn.model_selection import cross_val_score from sklearn.multiclass import OneVsRestClassifier from sklearn.linear_model import LogisticRegression 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 = LogisticRegression(solver="liblinear") 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. The dataset contains four features based on which the target variable can be …






0 Comments