Changeset 11397:e4b810f1f493 in orange
 Timestamp:
 03/12/13 17:02:59 (13 months ago)
 Branch:
 default
 Location:
 Orange
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

Orange/classification/logreg.py
r11063 r11397 2 2 from Orange.utils import deprecated_keywords, deprecated_members 3 3 from Orange.data import preprocess 4 from Orange.data.continuization import DomainContinuizer 4 5 import decimal 5 6 import math … … 1023 1024 """ 1024 1025 1025 from Orange.data import preprocess 1026 1026 1027 class LibLinearLogRegLearner(Orange.core.LinearLearner): 1027 1028 """A logistic regression learner from `LIBLINEAR`_. 1028 1029 1029 1030 Supports L2 regularized learning. 1030 1031 1031 1032 .. _`LIBLINEAR`: http://www.csie.ntu.edu.tw/~cjlin/liblinear/ 1032 1033 1033 1034 """ 1034 1035 … … 1040 1041 1041 1042 def __init__(self, solver_type=L2R_LR, C=1.0, eps=0.01, normalization=True, 1042 bias=1.0, **kwargs): 1043 bias=1.0, multinomial_treatment=DomainContinuizer.NValues, 1044 **kwargs): 1043 1045 """ 1044 :param solver_type: One of the following class constants: 1046 :param solver_type: One of the following class constants: 1045 1047 ``L2_LR``, ``L2_LR_DUAL``, ``L1R_LR``. 1046 1047 :param C: Regularization parameter (default 1.0). Higher values of C mean 1048 less regularization (C is a coefficient for the loss function). 1048 1049 :param C: Regularization parameter (default 1.0). Higher values of 1050 C mean less regularization (C is a coefficient for the loss 1051 function). 1049 1052 :type C: float 1050 1053 1051 1054 :param eps: Stopping criteria (default 0.01) 1052 1055 :type eps: float 1053 1056 1054 1057 :param normalization: Normalize the input data prior to learning 1055 1058 (default True) … … 1058 1061 :param bias: If positive, use it as a bias (default 1). 1059 1062 :type bias: float 1060 1063 1064 :param multinomial_treatment: Defines how to handle multinomial 1065 features for learning. It can be one of the 1066 :class:`~.DomainContinuizer` `multinomial_treatment` 1067 constants (default: `DomainContinuizer.NValues`). 1068 1069 :type multinomial_treatment: int 1070 1071 .. versionadded:: 2.6.1 1072 Added `multinomial_treatment` 1073 1061 1074 """ 1062 1075 self.solver_type = solver_type … … 1065 1078 self.normalization = normalization 1066 1079 self.bias = bias 1080 self.multinomial_treatment = multinomial_treatment 1067 1081 1068 1082 for name, value in kwargs.items(): … … 1074 1088 1075 1089 if data.domain.has_discrete_attributes(False) or self.normalization: 1076 dc = Orange.data.continuization.DomainContinuizer()1077 dc.multinomial_treatment = dc.NValues1090 dc = DomainContinuizer() 1091 dc.multinomial_treatment = self.multinomial_treatment 1078 1092 dc.class_treatment = dc.Ignore 1079 1093 dc.continuous_treatment = \ 1080 1094 dc.NormalizeByVariance if self.normalization else dc.Leave 1081 c_domain = dc(data) 1095 c_domain = dc(data) 1082 1096 data = data.translate(c_domain) 1083 1097 return super(LibLinearLogRegLearner, self).__call__(data, weight_id) 
Orange/classification/svm/__init__.py
r11377 r11397 20 20 21 21 from Orange.data import preprocess 22 from Orange.data.preprocess import DomainContinuizer 22 23 23 24 from Orange import feature as variable … … 805 806 806 807 def __init__(self, solver_type=L2R_L2LOSS_DUAL, C=1.0, eps=0.01, 807 bias=1.0, normalization=True, **kwargs): 808 bias=1.0, normalization=True, 809 multinomial_treatment=DomainContinuizer.NValues, **kwargs): 808 810 """ 809 811 :param solver_type: One of the following class constants: … … 833 835 :type normalization: bool 834 836 835 .. note:: If the training data contains discrete features they are 836 replaced by indicator columns one for each value of the feature 837 regardless of the value of `normalization`. This is different 838 then in :class:`SVMLearner` where this is done only if 837 :param multinomial_treatment: Defines how to handle multinomial 838 features for learning. It can be one of the 839 :class:`~.DomainContinuizer` `multinomial_treatment` 840 constants (default: `DomainContinuizer.NValues`). 841 842 :type multinomial_treatment: int 843 844 .. versionadded:: 2.6.1 845 Added `multinomial_treatment` 846 847 .. note:: By default if the training data contains discrete features 848 they are replaced by indicator columns one for each value of the 849 feature regardless of the value of `normalization`. This is 850 different then in :class:`SVMLearner` where this is done only if 839 851 `normalization` is ``True``. 840 852 … … 852 864 self.bias = bias 853 865 self.normalization = normalization 866 self.multinomial_treatment = multinomial_treatment 854 867 855 868 for name, val in kwargs.items(): 856 869 setattr(self, name, val) 870 857 871 if self.solver_type not in [self.L2R_L2LOSS_DUAL, self.L2R_L2LOSS, 858 872 self.L2R_L1LOSS_DUAL, self.L1R_L2LOSS]: 859 warnings.warn( """\860 Deprecated 'solver_type', use 861 'Orange.classification.logreg.LibLinearLogRegLearner' 862 to build a logistic regression model using LIBLINEAR. 863 """, 864 DeprecationWarning)873 warnings.warn( 874 " Deprecated 'solver_type', use " 875 "'Orange.classification.logreg.LibLinearLogRegLearner'" 876 "to build a logistic regression models using LIBLINEAR.", 877 DeprecationWarning 878 ) 865 879 866 880 def __call__(self, data, weight_id=None): … … 869 883 870 884 if data.domain.has_discrete_attributes(False) or self.normalization: 871 dc = Orange.data.continuization.DomainContinuizer()872 dc.multinomial_treatment = dc.NValues885 dc = DomainContinuizer() 886 dc.multinomial_treatment = self.multinomial_treatment 873 887 dc.class_treatment = dc.Ignore 874 888 dc.continuous_treatment = \ … … 888 902 889 903 def __init__(self, C=1.0, eps=0.01, bias=1.0, 890 normalization=True, **kwargs): 904 normalization=True, 905 multinomial_treatment=DomainContinuizer.NValues, 906 **kwargs): 891 907 """\ 892 908 :param C: Regularization parameter (default 1.0) … … 904 920 (default True) 905 921 :type normalization: bool 922 923 :param multinomial_treatment: Defines how to handle multinomial 924 features for learning. It can be one of the 925 :class:`~.DomainContinuizer` `multinomial_treatment` 926 constants (default: `DomainContinuizer.NValues`). 927 928 :type multinomial_treatment: int 929 930 .. versionadded:: 2.6.1 931 Added `multinomial_treatment` 906 932 907 933 """ … … 910 936 self.bias = bias 911 937 self.normalization = normalization 938 self.multinomial_treatment = multinomial_treatment 912 939 for name, val in kwargs.items(): 913 940 setattr(self, name, val) … … 920 947 921 948 if data.domain.has_discrete_attributes(False) or self.normalization: 922 dc = Orange.data.continuization.DomainContinuizer()923 dc.multinomial_treatment = dc.NValues949 dc = DomainContinuizer() 950 dc.multinomial_treatment = self.multinomial_treatment 924 951 dc.class_treatment = dc.Ignore 925 952 dc.continuous_treatment = \ 
Orange/testing/unit/tests/test_linear.py
r11017 r11397 5 5 from Orange.testing.testing import datasets_driven 6 6 from Orange.classification.svm import LinearSVMLearner 7 from Orange.data.preprocess import DomainContinuizer 7 8 try: 8 9 import unittest2 as unittest … … 11 12 12 13 import numpy as np 14 15 16 def clone(obj): 17 return cPickle.loads(cPickle.dumps(obj)) 13 18 14 19 … … 76 81 def test_learner_with_bias_on(self, dataset): 77 82 learner = self.learner 78 learner_b = c Pickle.loads(cPickle.dumps(learner))83 learner_b = clone(learner) 79 84 learner_b.bias = 1 80 85 try: … … 116 121 117 122 123 def multinomial_test(self): 124 data = Orange.data.Table("lenses") 125 learner = clone(self.learner) 126 learner.multinomial_treatment = DomainContinuizer.NValues 127 classifier = learner(data) 128 self.assertEqual(len(classifier.domain), 7) 129 130 learner.multinomial_treatment = DomainContinuizer.FrequentIsBase 131 classifier = learner(data) 132 self.assertEqual(len(classifier.domain), 6) 133 134 learner.multinomial_treatment = DomainContinuizer.ReportError 135 with self.assertRaises(Orange.core.KernelException): 136 classifier = learner(data) 137 138 118 139 @datasets_driven(datasets=testing.CLASSIFICATION_DATASETS) 119 140 class TestLinearSVMLearnerL2R_L2LOSS_DUAL(testing.LearnerTestCase): … … 123 144 test_learner_with_bias_on = test_learner_with_bias_on 124 145 test_missing_instances = missing_instances_test 146 test_multinomial = multinomial_test 125 147 126 148 … … 132 154 test_learner_with_bias_on = test_learner_with_bias_on 133 155 test_missing_instances = missing_instances_test 156 test_multinomial = multinomial_test 134 157 135 158 … … 141 164 test_learner_with_bias_on = test_learner_with_bias_on 142 165 test_missing_instances = missing_instances_test 166 test_multinomial = multinomial_test 143 167 144 168 … … 150 174 test_learner_with_bias_on = test_learner_with_bias_on 151 175 test_missing_instances = missing_instances_test 176 test_multinomial = multinomial_test 152 177 153 178 … … 159 184 test_learner_with_bias_on = test_learner_with_bias_on 160 185 test_missing_instances = missing_instances_test 186 test_multinomial = multinomial_test 161 187 162 188 … … 168 194 test_learner_with_bias_on = test_learner_with_bias_on 169 195 test_missing_instances = missing_instances_test 196 test_multinomial = multinomial_test 170 197 171 198
Note: See TracChangeset
for help on using the changeset viewer.