1010from Orange .widgets .utils .owlearnerwidget import OWBaseLearner
1111from Orange .widgets .utils .signals import Output
1212from Orange .widgets .utils .widgetpreview import WidgetPreview
13+ from Orange .classification import SklLearner
14+ from Orange .preprocess import Scale
1315
1416
1517class OWSVM (OWBaseLearner ):
@@ -26,6 +28,12 @@ class OWSVM(OWBaseLearner):
2628
2729 LEARNER = SVMLearner
2830
31+ pps = SklLearner .preprocessors
32+ scaling = [Scale (center = Scale .NoCentering )]
33+
34+ def __init__ (self ):
35+ super ().__init__ (SklLearner .preprocessors )
36+
2937 class Outputs (OWBaseLearner .Outputs ):
3038 support_vectors = Output ("Support vectors" , Table , explicit = True )
3139
@@ -56,13 +64,22 @@ class Outputs(OWBaseLearner.Outputs):
5664 limit_iter = Setting (True )
5765 #: maximum number of iterations
5866 max_iter = Setting (100 )
67+ #: scaling of data
68+ scale_data = Setting (True )
5969
6070 _default_gamma = "auto"
6171 kernels = (("Linear" , "x⋅y" ),
6272 ("Polynomial" , "(g x⋅y + c)<sup>d</sup>" ),
6373 ("RBF" , "exp(-g|x-y|²)" ),
6474 ("Sigmoid" , "tanh(g x⋅y + c)" ))
6575
76+ def set_preprocessor (self , preprocessor ):
77+ if preprocessor is None :
78+ self .preprocessors = self .pps
79+ else :
80+ self .preprocessors = preprocessor
81+ self .apply ()
82+
6683 def add_main_layout (self ):
6784 self ._add_type_box ()
6885 self ._add_kernel_box ()
@@ -176,6 +193,10 @@ def _add_optimization_box(self):
176193 alignment = Qt .AlignRight , controlWidth = 100 ,
177194 callback = self .settings_changed ,
178195 checkCallback = self .settings_changed )
196+ self .scaling_box = gui .checkBox (
197+ self .optimization_box , self ,
198+ 'scale_data' , label = 'Scale data' ,
199+ callback = self .settings_changed )
179200
180201 def _show_right_kernel (self ):
181202 enabled = [[False , False , False ], # linear
@@ -210,7 +231,7 @@ def create_learner(self):
210231 'probability' : True ,
211232 'tol' : self .tol ,
212233 'max_iter' : self .max_iter if self .limit_iter else - 1 ,
213- 'preprocessors' : self .preprocessors
234+ 'preprocessors' : list ( self . preprocessors ) + self . scaling if self . scale_data else self .preprocessors
214235 }
215236 if self .svm_type == self .SVM :
216237 return SVMLearner (C = self .C , epsilon = self .epsilon , ** common_args )
0 commit comments