-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[WIP] loss function name consistency #3556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -450,6 +450,7 @@ def _update_terminal_region(self, tree, terminal_regions, leaf, X, y, | |
|
||
LOSS_FUNCTIONS = {'ls': LeastSquaresError, | ||
'lad': LeastAbsoluteError, | ||
'absolute': LeastAbsoluteError, | ||
'huber': HuberLossFunction, | ||
'quantile': QuantileLossFunction, | ||
'bdeviance': BinomialDeviance, | ||
|
@@ -1239,12 +1240,13 @@ class GradientBoostingRegressor(BaseGradientBoosting, RegressorMixin): | |
|
||
Parameters | ||
---------- | ||
loss : {'ls', 'lad', 'huber', 'quantile'}, optional (default='ls') | ||
loss function to be optimized. 'ls' refers to least squares | ||
regression. 'lad' (least absolute deviation) is a highly robust | ||
loss function solely based on order information of the input | ||
loss : {'ls', 'lad', 'absolute', huber', 'quantile'}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you got it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would mention only absolute and not lad in the docstring. Same for squared. |
||
optional (default='ls') loss function to be optimized. 'ls' refers to | ||
least squares regression. 'lad' (least absolute deviation) is a highly | ||
robust loss function solely based on order information of the input | ||
variables. 'huber' is a combination of the two. 'quantile' | ||
allows quantile regression (use `alpha` to specify the quantile). | ||
'absolute' is equivalent to 'lad'. | ||
|
||
learning_rate : float, optional (default=0.1) | ||
learning rate shrinks the contribution of each tree by `learning_rate`. | ||
|
@@ -1368,7 +1370,7 @@ class GradientBoostingRegressor(BaseGradientBoosting, RegressorMixin): | |
Elements of Statistical Learning Ed. 2, Springer, 2009. | ||
""" | ||
|
||
_SUPPORTED_LOSS = ('ls', 'lad', 'huber', 'quantile') | ||
_SUPPORTED_LOSS = ('ls', 'lad', 'huber', 'quantile', 'absolute') | ||
|
||
def __init__(self, loss='ls', learning_rate=0.1, n_estimators=100, | ||
subsample=1.0, min_samples_split=2, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,11 @@ class LinearSVC(BaseLibLinear, LinearClassifierMixin, _LearntSelectorMixin, | |
C : float, optional (default=1.0) | ||
Penalty parameter C of the error term. | ||
|
||
loss : string, 'l1' or 'l2' (default='l2') | ||
loss : string, {'l1', 'l2', 'hinge', 'squared_hinge', 'lr'} (default='l2') | ||
Specifies the loss function. 'l1' is the hinge loss (standard SVM) | ||
while 'l2' is the squared hinge loss. | ||
while 'l2' is the squared hinge loss. 'hinge' is equivalent to 'l1', | ||
'squared_hinge' is equivalent to 'l2', 'lr' is the logistic | ||
regression | ||
|
||
penalty : string, 'l1' or 'l2' (default='l2') | ||
Specifies the norm used in the penalization. The 'l2' | ||
|
@@ -135,7 +137,15 @@ class frequencies. | |
|
||
def __init__(self, penalty='l2', loss='l2', dual=True, tol=1e-4, C=1.0, | ||
multi_class='ovr', fit_intercept=True, intercept_scaling=1, | ||
class_weight=None, verbose=0, random_state=None, max_iter=1000): | ||
class_weight=None, verbose=0, random_state=None, | ||
max_iter=1000): | ||
# make aliases for loss functions | ||
loss = loss.lower().strip() | ||
if loss == "hinge": | ||
loss = "l1" | ||
if loss == "squared_hinge": | ||
loss = "l2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see, I'll leave this out then. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, because the init method sets self.loss to loss, will this actually be a problem? If someone were to create an object with |
||
|
||
super(LinearSVC, self).__init__( | ||
penalty=penalty, loss=loss, dual=dual, tol=tol, C=C, | ||
multi_class=multi_class, fit_intercept=fit_intercept, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -433,13 +433,15 @@ def test_linearsvc_parameters(): | |
""" | ||
# generate list of possible parameter combinations | ||
params = [(dual, loss, penalty) for dual in [True, False] | ||
for loss in ['l1', 'l2', 'lr'] for penalty in ['l1', 'l2']] | ||
for loss in ['l1', 'l2', 'HINGE', ' squared_hinge', 'lr'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HINGE => hinge |
||
for penalty in ['l1', 'l2']] | ||
|
||
for dual, loss, penalty in params: | ||
if loss == 'l1' and penalty == 'l1': | ||
if ((loss == 'l1' or loss == 'HINGE') and penalty == 'l1'): | ||
assert_raises(ValueError, svm.LinearSVC, penalty=penalty, | ||
loss=loss, dual=dual) | ||
elif loss == 'l1' and penalty == 'l2' and not dual: | ||
elif ((loss == 'l1' or loss == 'HINGE') and penalty == 'l2' | ||
and not dual): | ||
assert_raises(ValueError, svm.LinearSVC, penalty=penalty, | ||
loss=loss, dual=dual) | ||
elif penalty == 'l1' and dual: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add "squared".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, actually SGD is using "squared_loss"... The "_loss" suffix is not consistent :-/ I would add the "squared" alias to SGD as well (and make it the default loss for SGDRegressor).