Skip to content

Commit 3e2d432

Browse files
committed
LogisticRegressionLearner: do not use MajorityLearner when one class
1 parent c708536 commit 3e2d432

File tree

2 files changed

+0
-23
lines changed

2 files changed

+0
-23
lines changed

Orange/classification/logistic_regression.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import warnings
2-
31
import numpy as np
4-
52
import sklearn.linear_model as skl_linear_model
63

7-
import Orange
84
from Orange.classification import SklLearner, SklModel
95
from Orange.preprocess import Normalize
106
from Orange.preprocess.score import LearnerScorer
@@ -44,12 +40,3 @@ def __init__(self, penalty="l2", dual=False, tol=0.0001, C=1.0,
4440
multi_class='ovr', verbose=0, n_jobs=1, preprocessors=None):
4541
super().__init__(preprocessors=preprocessors)
4642
self.params = vars()
47-
48-
def __call__(self, data):
49-
if len(np.unique(data.Y)) > 1:
50-
return super().__call__(data)
51-
else:
52-
warnings.warn("Single class in data, returning Constant Model.")
53-
maj = Orange.classification.MajorityLearner()
54-
const = maj(data)
55-
return const

Orange/tests/test_logistic_regression.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,6 @@ def test_predict_on_instance(self):
119119
probs2 = m(self.zoo[50, :], m.Probs)
120120
np.testing.assert_almost_equal(probs, probs2[0])
121121

122-
def test_single_class(self):
123-
t = self.iris[60:90]
124-
self.assertEqual(len(np.unique(t.Y)), 1)
125-
learn = LogisticRegressionLearner()
126-
with self.assertWarns(UserWarning):
127-
model = learn(t)
128-
self.assertEqual(model(t[0]), 1)
129-
self.assertTrue(np.all(model(t[0], ret=Model.Probs) == [0, 1, 0]))
130-
self.assertTrue(np.all(model(t) == 1))
131-
132122
def test_sklearn_single_class(self):
133123
t = self.iris[60:90]
134124
self.assertEqual(len(np.unique(t.Y)), 1)

0 commit comments

Comments
 (0)