Finding subsets for a robust regression
Gerard flanagan
grflanagan at gmail.com
Mon Sep 29 17:12:19 EDT 2008
Gerard flanagan wrote:
> tkpmep at hotmail.com wrote:
>
>>
>> x1 = [] #unique instances of x and y
>> y1 = [] #median(y) for each unique value of x
>> for xx,yy in d.iteritems():
>> x1.append(xx)
>> l = len(yy)
>> if l == 1:
>> y1.append(yy[0])
>> else:
>> yy.sort()
>> y1.append( (yy[l//2-1] + yy[l//2])/2.0 if l % 2 == 0 else
>> yy[l//2] )
>> --
>
> Not tested, but is this equivalent?
>
> x1 = []
> y1 = []
> for xx, yy in d.iteritems():
> L = len(yy) // 2
> yy.sort()
> y1.append(yy[L])
> if not L & 1:
> y1[-1] = (y1[-1] + yy[L-1]) / 2.0
>
> It means that you have a pointless 'sort' when len(yy) == 1, but then
> you save an 'if' per-iteration.
>
> G.
>
> --
Maybe that should be:
if L and not L & 1:
...
anyway...
More information about the Python-list
mailing list