Changes in Orange/classification/logreg.py [11063:68bc42e33a2a:11398:7e9b4eb30015] in orange
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Orange/classification/logreg.py
r11063 r11398 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 … … 920 921 ## PROBABILITY CALCULATIONS 921 922 922 def lchisqprob(chisq, df):923 def lchisqprob(chisq, df): 923 924 """ 924 925 Return the (1tailed) probability value associated with the provided … … 926 927 """ 927 928 BIG = 20.0 929 928 930 def ex(x): 929 930 931 932 933 934 if chisq <= 0 or df < 1:935 931 BIG = 20.0 932 if x < BIG: 933 return 0.0 934 else: 935 return math.exp(x) 936 if chisq <= 0 or df < 1: 937 return 1.0 936 938 a = 0.5 * chisq 937 if df %2 == 0:938 939 if df % 2 == 0: 940 even = 1 939 941 else: 940 942 even = 0 941 943 if df > 1: 942 944 y = ex(a) 943 945 if even: 944 946 s = y 945 947 else: 946 948 s = 2.0 * zprob(math.sqrt(chisq)) … … 953 955 if a > BIG: 954 956 if even: 955 957 e = 0.0 956 958 else: 957 959 e = math.log(math.sqrt(math.pi)) 958 960 c = math.log(a) 959 961 while (z <= chisq): 960 961 s = s + ex(c*zae)962 962 e = math.log(z) + e 963 s = s + ex(c * z  a  e) 964 z = z + 1.0 963 965 return s 964 966 else: … … 969 971 c = 0.0 970 972 while (z <= chisq): 971 e = e * (a /float(z))973 e = e * (a / float(z)) 972 974 c = c + e 973 975 z = z + 1.0 974 return (c *y+s)976 return (c * y + s) 975 977 else: 976 978 return s … … 980 982 """ 981 983 Returns the area under the normal curve 'to the left of' the given z value. 982 Thus:: 984 Thus:: 983 985 984 986 for z<0, zprob(z) = 1tail probability … … 990 992 Z_MAX = 6.0 # maximum meaningful zvalue 991 993 if z == 0.0: 992 994 x = 0.0 993 995 else: 994 995 if y >= (Z_MAX*0.5):996 997 998 w = y*y999 1000 0.001075204047) * w +0.005198775019) * w1001 0.019198292004) * w +0.059054035642) * w1002 0.151968751364) * w +0.319152932694) * w1003 0.531923007300) * w +0.797884560593) * y * 2.01004 1005 1006 1007 +0.000152529290) * y 0.000019538132) * y1008 0.000676904986) * y +0.001390604284) * y1009 0.000794620820) * y 0.002034254874) * y1010 +0.006549791214) * y 0.010557625006) * y1011 +0.011630447319) * y 0.009279453341) * y1012 +0.005353579108) * y 0.002141268741) * y1013 +0.000535310849) * y +0.999936657524996 y = 0.5 * math.fabs(z) 997 if y >= (Z_MAX * 0.5): 998 x = 1.0 999 elif (y < 1.0): 1000 w = y * y 1001 x = ((((((((0.000124818987 * w 1002  0.001075204047) * w + 0.005198775019) * w 1003  0.019198292004) * w + 0.059054035642) * w 1004  0.151968751364) * w + 0.319152932694) * w 1005  0.531923007300) * w + 0.797884560593) * y * 2.0 1006 else: 1007 y = y  2.0 1008 x = (((((((((((((0.000045255659 * y 1009 + 0.000152529290) * y  0.000019538132) * y 1010  0.000676904986) * y + 0.001390604284) * y 1011  0.000794620820) * y  0.002034254874) * y 1012 + 0.006549791214) * y  0.010557625006) * y 1013 + 0.011630447319) * y  0.009279453341) * y 1014 + 0.005353579108) * y  0.002141268741) * y 1015 + 0.000535310849) * y + 0.999936657524 1014 1016 if z > 0.0: 1015 prob = ((x+1.0)*0.5)1017 prob = ((x + 1.0) * 0.5) 1016 1018 else: 1017 prob = ((1.0x)*0.5)1019 prob = ((1.0  x) * 0.5) 1018 1020 return prob 1019 1021 … … 1023 1025 """ 1024 1026 1025 from Orange.data import preprocess 1027 1026 1028 class LibLinearLogRegLearner(Orange.core.LinearLearner): 1027 1029 """A logistic regression learner from `LIBLINEAR`_. 1028 1030 1029 1031 Supports L2 regularized learning. 1030 1032 1031 1033 .. _`LIBLINEAR`: http://www.csie.ntu.edu.tw/~cjlin/liblinear/ 1032 1034 1033 1035 """ 1034 1036 … … 1040 1042 1041 1043 def __init__(self, solver_type=L2R_LR, C=1.0, eps=0.01, normalization=True, 1042 bias=1.0, **kwargs): 1044 bias=1.0, multinomial_treatment=DomainContinuizer.NValues, 1045 **kwargs): 1043 1046 """ 1044 :param solver_type: One of the following class constants: 1047 :param solver_type: One of the following class constants: 1045 1048 ``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). 1049 1050 :param C: Regularization parameter (default 1.0). Higher values of 1051 C mean less regularization (C is a coefficient for the loss 1052 function). 1049 1053 :type C: float 1050 1054 1051 1055 :param eps: Stopping criteria (default 0.01) 1052 1056 :type eps: float 1053 1057 1054 1058 :param normalization: Normalize the input data prior to learning 1055 1059 (default True) … … 1058 1062 :param bias: If positive, use it as a bias (default 1). 1059 1063 :type bias: float 1060 1064 1065 :param multinomial_treatment: Defines how to handle multinomial 1066 features for learning. It can be one of the 1067 :class:`~.DomainContinuizer` `multinomial_treatment` 1068 constants (default: `DomainContinuizer.NValues`). 1069 1070 :type multinomial_treatment: int 1071 1072 .. versionadded:: 2.6.1 1073 Added `multinomial_treatment` 1074 1061 1075 """ 1062 1076 self.solver_type = solver_type … … 1065 1079 self.normalization = normalization 1066 1080 self.bias = bias 1081 self.multinomial_treatment = multinomial_treatment 1067 1082 1068 1083 for name, value in kwargs.items(): … … 1074 1089 1075 1090 if data.domain.has_discrete_attributes(False) or self.normalization: 1076 dc = Orange.data.continuization.DomainContinuizer()1077 dc.multinomial_treatment = dc.NValues1091 dc = DomainContinuizer() 1092 dc.multinomial_treatment = self.multinomial_treatment 1078 1093 dc.class_treatment = dc.Ignore 1079 1094 dc.continuous_treatment = \ 1080 1095 dc.NormalizeByVariance if self.normalization else dc.Leave 1081 c_domain = dc(data) 1096 c_domain = dc(data) 1082 1097 data = data.translate(c_domain) 1083 1098 return super(LibLinearLogRegLearner, self).__call__(data, weight_id)
Note: See TracChangeset
for help on using the changeset viewer.