Orange Forum • View topic - Alternative to _, in Classifier with Feature Selection

Alternative to _, in Classifier with Feature Selection

A place to ask questions about methods in Orange and how they are used and other general support.

Alternative to _, in Classifier with Feature Selection

Postby sreastman » Wed Jan 30, 2013 17:16

The final section of the latest tutorial, Classification with Feature Selection, uses "_," in the following code:

class OptimizedSmallLearner(Orange.classification.PyLearner):
def __init__(self, name="opt_small", ms=range(1,30,3)):
self.ms = ms
self.name = name

def __call__(self, data, weight=None):
scores = []
for m in self.ms:
res = Orange.evaluation.testing.cross_validation([SmallLearner(m=m)], data, folds=5)
scores.append((Orange.evaluation.scoring.AUC(res)[0], m))
_, best_m = max(scores)

return SmallLearner(data, m=best_m)

Here it is "absorbing" the first part of the tuple returned by max(scores) so best_m may hold the second part. Those who want to stay away from "_" because it is easy for the interpreter to malfunction with it or just because it looks confusing to a newby, may want to substitute this line for the one with "_,":

best_m = max(scores)[1]

Steve

Steve

Re: Alternative to _, in Classifier with Feature Selection

Postby Ales » Thu Jan 31, 2013 10:54

What do you mean by
sreastman wrote:because it is easy for the interpreter to malfunction
Can you provide an example.

Re: Alternative to _, in Classifier with Feature Selection

Postby sreastman » Thu Jan 31, 2013 13:55

Here is an exmaple of what I am talking about:

>>> x = 0
>>> list = [11, -3, 5, 17]
>>> for i in range(len(list)):
... x += list[i]**2
...
>>> x
444
>>> _
444
>>> x = 5
>>> _
444


Return to Questions & Support



cron