Changeset 8141:1e2e8b53c6fd in orange
 Timestamp:
 08/02/11 17:03:29 (3 years ago)
 Branch:
 default
 Convert:
 0c110d79887d2e883079c9d932e0184d43cbec48
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

orange/Orange/regression/earth.py
r8135 r8141 45 45 .. autofunction:: plot_evimp 46 46 47 .. autofunction:: bagged_evimp 48 47 49 """ 48 50 … … 66 68 def __init__(self, degree=1, terms=21, penalty= None, thresh=1e3, 67 69 min_span=0, new_var_penalty=0, fast_k=20, fast_beta=1, 68 pruned_terms=None, scale_resp= False, store_examples=True,70 pruned_terms=None, scale_resp=True, store_examples=True, 69 71 multi_label=False, **kwds): 70 72 """ Initialize the learner instance. … … 132 134 x = data[:, ~ label_mask] 133 135 136 if self.scale_resp: 137 y = y  numpy.mean(y, axis=0) 138 y = y / numpy.std(y, axis=1) 139 140 134 141 # TODO: y scaling 135 142 n_terms, used, bx, dirs, cuts = forward_pass(x, y, … … 456 463 use_beta_cache = True 457 464 465 # These tests are performed in ForwardPass, and if they fail the function 466 # calls exit. So we must check it here and raise a exception to avoid a 467 # process shutdown. 468 if n_cases < 8: 469 raise ValueError("Need at least 8 data instances.") 470 if n_cases > 1e8: 471 raise ValueError("To many data instances.") 472 if n_resp < 1: 473 raise ValueError("No response column.") 474 if n_resp > 1e6: 475 raise ValueError("To many response columns.") 476 if n_preds < 1: 477 raise ValueError("No predictor columns.") 478 if n_preds > 1e5: 479 raise ValueError("To many predictor columns.") 480 if degree <= 0 or degree > 100: 481 raise ValueError("Invalid 'degree'.") 482 if terms < 3 or terms > 10000: 483 raise ValueError("'terms' must be in >= 3 and <= 10000.") 484 if penalty < 0 and penalty != 1: 485 raise ValueError("Invalid 'penalty' (the only legal negative value is 1).") 486 if penalty > 1000: 487 raise ValueError("Invalid 'penalty' (must be <= 1000).") 488 if thresh < 0.0 or thresh >= 1.0: 489 raise ValueError("Invalid 'thresh' (must be in [0.0, 1.0) ).") 490 if fast_beta < 0 or fast_beta > 1000: 491 raise ValueError("Invalid 'fast_beta' (must be in [0, 1000] ).") 492 if new_var_penalty < 0 or new_var_penalty > 10: 493 raise ValueError("Invalid 'new_var_penalty' (must be in [0, 10] ).") 494 if (numpy.var(y, axis=0) <= 1e8).any(): 495 raise ValueError("Variance of y is zero (or near zero).") 496 458 497 _c_forward_pass_(ctypes.byref(n_term), full_set, bx, dirs, cuts, 459 498 n_factors_in_terms, n_uses, x, y, weights, n_cases, … … 598 637 599 638 axes1.yaxis.set_label_text("nsubsets") 600 axes2.yaxis.set_label_text("normalize s gccor rss")639 axes2.yaxis.set_label_text("normalized gcv or rss") 601 640 602 641 axes1.legend([l1, l2, l3], ["nsubsets", "gcv", "rss"]) … … 604 643 fig.show() 605 644 645 def bagged_evimp(classifier, used_only=True): 646 """ Extract combined (average) evimp from an instance of BaggedClassifier 647 648 Example: :: 649 >>> from Orange.ensemble.bagging import BaggedLearner 650 >>> bc = BaggedLearner(EarthLearner(degree=3, terms=10), data) 651 >>> bagged_evimp(bc) 652 653 """ 654 def assert_type(object, class_): 655 if not isinstance(object, class_): 656 raise TypeError("Instance of %r expected." % (class_)) 657 from collections import defaultdict 658 from Orange.ensemble.bagging import BaggedClassifier 659 660 assert_type(classifier, BaggedClassifier) 661 bagged_imp = defaultdict(list) 662 663 for c in classifier.classifiers: 664 assert_type(c, EarthClassifier) 665 imp = evimp(c, used_only=False) 666 for attr, score in imp: 667 bagged_imp[attr].append(score) 668 669 for attr, scores in bagged_imp.items(): 670 scores = numpy.average(scores, axis=0) 671 bagged_imp[attr] = tuple(scores) 672 673 bagged_imp = sorted(bagged_imp.items(), key=lambda t:t[1][0], 674 reverse=True) 675 if used_only: 676 bagged_imp = [(a, r) for a, r in bagged_imp if r[0] > 0] 677 return bagged_imp 606 678 607 679 """
Note: See TracChangeset
for help on using the changeset viewer.