Skip to content

Commit

Permalink
Modified SGD widget, SGDClassifier and SGDRegressionLearner to comply…
Browse files Browse the repository at this point in the history
… with sklearn 0.21 changes (tol and max_iter)
  • Loading branch information
smiks committed Feb 22, 2018
1 parent 60c741f commit 936cf1f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Orange/classification/sgd.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SGDClassificationLearner(SklLearner):
preprocessors = SklLearner.preprocessors + [Normalize()]

def __init__(self, loss='hinge', penalty='l2', alpha=0.0001,
l1_ratio=0.15,fit_intercept=True, max_iter=5,
l1_ratio=0.15, fit_intercept=True, max_iter=5,
tol=None, shuffle=True, epsilon=0.1, random_state=None,
learning_rate='invscaling', eta0=0.01, power_t=0.25,
warm_start=False, average=False, preprocessors=None):
Expand Down
4 changes: 2 additions & 2 deletions Orange/regression/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class SGDRegressionLearner(LinearRegressionLearner):
preprocessors = SklLearner.preprocessors + [Normalize()]

def __init__(self, loss='squared_loss', penalty='l2', alpha=0.0001,
l1_ratio=0.15, fit_intercept=True, n_iter=5, shuffle=True,
epsilon=0.1, n_jobs=1, random_state=None,
l1_ratio=0.15, fit_intercept=True, max_iter=5, tol=None,
shuffle=True, epsilon=0.1, n_jobs=1, random_state=None,
learning_rate='invscaling', eta0=0.01, power_t=0.25,
class_weight=None, warm_start=False, average=False,
preprocessors=None):
Expand Down
18 changes: 11 additions & 7 deletions Orange/widgets/model/owsgd.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class Outputs(OWBaseLearner.Outputs):
learning_rate_index = Setting(0)
eta0 = Setting(.01)
power_t = Setting(.25)
max_iter = Setting(5)
max_iter = Setting(1000)
tol = Setting(1e-3)

def add_main_layout(self):
self._add_algorithm_to_layout()
Expand Down Expand Up @@ -154,6 +155,13 @@ def _add_learning_params_to_layout(self):
box, self, 'max_iter', 1, MAXINT - 1, label='Number of iterations: ',
controlWidth=80, alignment=Qt.AlignRight,
callback=self.settings_changed)

self.tol_spin = gui.spin(
box, self, 'tol', 0, 10., .1e-3, spinType=float, controlWidth=80,
label='Tolerance (stopping criterion): ', alignment=Qt.AlignRight,
callback=self.settings_changed)
gui.separator(box, height=12)

# Wrap shuffle_cbx inside another hbox to align it with the random_seed
# spin box on OSX
self.shuffle_cbx = gui.checkBox(
Expand Down Expand Up @@ -247,6 +255,7 @@ def create_learner(self):
eta0=self.eta0,
power_t=self.power_t,
max_iter=self.max_iter,
tol=self.tol,
preprocessors=self.preprocessors,
**params)

Expand Down Expand Up @@ -306,11 +315,6 @@ def update_model(self):
coeffs.name = "coefficients"
self.Outputs.coefficients.send(coeffs)

@classmethod
def migrate_settings(cls, settings_, version):
if version < 2:
settings_["max_iter"] = settings_.pop("n_iter", 5)


if __name__ == '__main__':
import sys
Expand All @@ -324,4 +328,4 @@ def migrate_settings(cls, settings_, version):
ow.set_data(d)
ow.show()
a.exec_()
ow.saveSettings()
ow.saveSettings()

0 comments on commit 936cf1f

Please sign in to comment.