Skip to content

Commit

Permalink
Merge pull request #1448 from sstanovnik/fix-logreg-weights
Browse files Browse the repository at this point in the history
[FIX] Stop advertising support for weights in LogisticRegression.
  • Loading branch information
lanzagar authored Jul 13, 2016
2 parents d6a324e + c5d211b commit 7a6c034
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Orange/classification/logistic_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ def __init__(self, penalty="l2", dual=False, tol=0.0001, C=1.0,
random_state=None, preprocessors=None):
super().__init__(preprocessors=preprocessors)
self.params = vars()

@property
def supports_weights(self):
# liblinear (default) cannot handle weights
return False
22 changes: 19 additions & 3 deletions Orange/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import unittest

from Orange.base import SklLearner
from Orange.regression import LinearRegressionLearner
from Orange.classification import LogisticRegressionLearner
from Orange.data import Table

from sklearn.linear_model import LogisticRegression


class TestSklLearner(unittest.TestCase):
Expand All @@ -26,7 +30,19 @@ class DummyLearner(SklLearner):

self.assertFalse(DummyLearner().supports_weights)

def test_logreg(self):
self.assertTrue(LogisticRegressionLearner().supports_weights,
"Either LogisticRegression no longer supports weighted tables"
def test_linreg(self):
self.assertTrue(LinearRegressionLearner().supports_weights,
"Either LinearRegression no longer supports weighted tables "
"or SklLearner.supports_weights is out-of-date.")

def test_logreg(self):
self.assertFalse(LogisticRegressionLearner().supports_weights,
"Logistic regression has its supports_weights overridden because "
"liblinear doesn't support them (even though the parameter exists)")

def test_assert_liblinear_doesnt_accept_weights(self):
data = Table('iris')
data.set_weights(1.2)
with self.assertRaises(ValueError):
skl = LogisticRegression(solver='liblinear')
skl.fit(data.X, data.Y, data.W)

0 comments on commit 7a6c034

Please sign in to comment.