Changeset 10955:8fd59ece1784 in orange
 Timestamp:
 07/19/12 12:57:55 (21 months ago)
 Branch:
 default
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Orange/classification/svm/__init__.py
r10954 r10955 25 25 from Orange.utils import _orange__new__ 26 26 27 27 28 def max_nu(data): 28 29 """ 29 30 Return the maximum nu parameter for the given data table for 30 31 Nu_SVC learning. 31 32 32 33 :param data: Data with discrete class variable 33 34 :type data: Orange.data.Table 34 35 35 36 """ 36 37 nu = 1.0 37 38 dist = list(Orange.core.Distribution(data.domain.classVar, data)) 39 38 40 def pairs(seq): 39 41 for i, n1 in enumerate(seq): … … 62 64 :param degree: kernel parameter (only for ``Polynomial``) 63 65 :type degree: int 64 :param gamma: kernel parameter; if 0, it is set to 1.0/#features (for ``Polynomial``, ``RBF`` and ``Sigmoid``) 66 :param gamma: kernel parameter; if 0, it is set to 1.0/#features 67 (for ``Polynomial``, ``RBF`` and ``Sigmoid``) 65 68 :type gamma: float 66 69 :param coef0: kernel parameter (for ``Polynomial`` and ``Sigmoid``) … … 81 84 :param probability: build a probability model 82 85 :type probability: bool 83 :param shrinking: use shrinking heuristics 86 :param shrinking: use shrinking heuristics 84 87 :type shrinking: bool 85 88 :param normalization: normalize the input data prior to learning … … 88 91 :param weight: a list of class weights 89 92 :type weight: list 93 :param verbose: If `True` show training progress (default is `False`). 94 :type verbose: bool 90 95 91 96 Example: 92 97 93 98 >>> import Orange 94 99 >>> from Orange.classification import svm … … 101 106 >>> print "AUC: %.4f" % scoring.AUC(results)[0] 102 107 AUC: 0.9565 103 104 108 105 109 """ 106 110 __new__ = _orange__new__(_SVMLearner) … … 142 146 def __call__(self, data, weight=0): 143 147 """Construct a SVM classifier 144 148 145 149 :param table: data with continuous features 146 150 :type table: Orange.data.Table 147 151 148 152 :param weight: ignored (required due to base class signature); 149 153 """ … … 158 162 isinstance(class_var, Orange.feature.Continuous): 159 163 self.svm_type += 3 160 #raise AttributeError, "Cannot learn a discrete classifier from non descrete class data. Use EPSILON_SVR or NU_SVR for regression" 164 161 165 if self.svm_type in [3, 4] and \ 162 166 isinstance(class_var, Orange.feature.Discrete): 163 167 self.svm_type = 3 164 #raise AttributeError, "Cannot do regression on descrete class data. Use C_SVC or NU_SVC for classification" 168 165 169 if self.kernel_type == kernels.Custom and not self.kernel_func: 166 170 raise ValueError("Custom kernel function not supplied") 167 171 168 import warnings169 170 172 nu = self.nu 171 if self.svm_type == SVMLearner.Nu_SVC: #is nu feasible 173 if self.svm_type == SVMLearner.Nu_SVC: 174 # Check if nu is feasible 172 175 max_nu = self.max_nu(examples) 173 176 if self.nu > max_nu: … … 181 184 "verbose", "cache_size", "eps"]: 182 185 setattr(self.learner, name, getattr(self, name)) 186 183 187 self.learner.nu = nu 184 188 self.learner.set_weights(self.weight) … … 186 190 if self.svm_type == SVMLearner.OneClass and self.probability: 187 191 self.learner.probability = False 188 warnings.warn("Oneclass SVM probability output not supported yet.")192 warnings.warn("Oneclass SVM probability output not supported.") 189 193 return self.learn_classifier(examples) 190 194 … … 198 202 def tune_parameters(self, data, parameters=None, folds=5, verbose=0, 199 203 progress_callback=None): 200 """Tune the ``parameters`` on the given ``data`` using 204 """Tune the ``parameters`` on the given ``data`` using 201 205 internal cross validation. 202 206 203 207 :param data: data for parameter tuning 204 :type data: Orange.data.Table 208 :type data: Orange.data.Table 205 209 :param parameters: names of parameters to tune 206 210 (default: ["nu", "C", "gamma"]) … … 212 216 :param progress_callback: callback function for reporting progress 213 217 :type progress_callback: callback function 214 218 215 219 Here is example of tuning the `gamma` parameter using 216 220 3fold cross validation. :: … … 218 222 svm = Orange.classification.svm.SVMLearner() 219 223 svm.tune_parameters(table, parameters=["gamma"], folds=3) 220 224 221 225 """ 222 226 … … 233 237 if self.svm_type in [SVMLearner.Nu_SVC, SVMLearner.Nu_SVR] \ 234 238 and "nu" in parameters: 235 numOfNuValues = 9236 239 if isinstance(data.domain.class_var, variable.Discrete): 237 240 max_nu = max(self.max_nu(data)  1e7, 0.0) … … 242 245 elif "C" in parameters: 243 246 searchParams.append(("C", [2 ** a for a in range(5, 15, 2)])) 247 244 248 if self.kernel_type == 2 and "gamma" in parameters: 245 searchParams.append(("gamma", [2 ** a for a in range(5, 5, 2)] + [0])) 249 searchParams.append(("gamma", 250 [2 ** a for a in range(5, 5, 2)] + [0]) 251 ) 246 252 tunedLearner = orngWrap.TuneMParameters(object=self, 247 253 parameters=searchParams, … … 249 255 returnWhat=orngWrap.TuneMParameters.returnLearner, 250 256 progressCallback=progress_callback 251 if progress_callback else lambda i: None)257 if progress_callback else lambda i: None) 252 258 tunedLearner(data, verbose=verbose) 253 259 if normalization: … … 539 545 def __reduce__(self): 540 546 return SVMClassifier, (self.__wrapped,), dict(self.__dict__) 541 547 542 548 def get_binary_classifier(self, c1, c2): 543 549 """Return a binary classifier for classes `c1` and `c2`. … … 546 552 if self.svm_type not in [SVMLearner.C_SVC, SVMLearner.Nu_SVC]: 547 553 raise TypeError("SVM classification model expected.") 548 554 549 555 c1 = int(self.class_var(c1)) 550 556 c2 = int(self.class_var(c2)) 551 557 552 558 n_class = len(self.class_var.values) 553 559 554 560 if c1 == c2: 555 561 raise ValueError("Different classes expected.") 556 562 557 563 bin_class_var = Orange.feature.Discrete("%s vs %s" % \ 558 564 (self.class_var.values[c1], self.class_var.values[c2]), 559 565 values=["0", "1"]) 560 566 561 567 mult = 1.0 562 568 if c1 > c2: 563 569 c1, c2 = c2, c1 564 570 mult = 1.0 565 566 classifier_i = n_class * (n_class  1) / 2  (n_class  c1  1) * (n_class  c1  2) / 2  (n_class  c2) 567 571 572 classifier_i = n_class * (n_class  1) / 2  \ 573 (n_class  c1  1) * (n_class  c1  2) / 2  \ 574 (n_class  c2) 575 568 576 coef = self.coef[classifier_i] 569 577 570 578 coef1 = [(mult * alpha, sv_i) for alpha, sv_i in coef \ 571 579 if int(self.support_vectors[sv_i].get_class()) == c1] 572 580 coef2 = [(mult * alpha, sv_i) for alpha, sv_i in coef \ 573 if int(self.support_vectors[sv_i].get_class()) == c2] 574 581 if int(self.support_vectors[sv_i].get_class()) == c2] 582 575 583 rho = mult * self.rho[classifier_i] 576 577 model = self._binary_libsvm_model_string(bin_class_var, 584 585 model = self._binary_libsvm_model_string(bin_class_var, 578 586 [coef1, coef2], 579 587 [rho]) 580 588 581 589 all_sv = [self.support_vectors[sv_i] \ 582 for c, sv_i in coef1 + coef2] 583 590 for c, sv_i in coef1 + coef2] 591 584 592 all_sv = Orange.data.Table(all_sv) 585 593 586 594 svm_classifier_type = type(self.__wrapped) 587 595 588 596 # Build args for svm_classifier_type constructor 589 597 args = (bin_class_var, self.examples, all_sv, model) 590 598 591 599 if isinstance(svm_classifier_type, _SVMClassifierSparse): 592 600 args = args + (int(self.__wrapped.use_non_meta),) 593 601 594 602 if self.kernel_type == kernels.Custom: 595 603 args = args + (self.kernel_func,) 596 604 597 605 native_classifier = svm_classifier_type(*args) 598 606 return SVMClassifier(native_classifier) 599 607 600 608 def _binary_libsvm_model_string(self, class_var, coef, rho): 601 609 """Return a libsvm formated model string for binary classifier 602 610 """ 603 611 import itertools 604 612 605 613 if not isinstance(self.class_var, variable.Discrete): 606 614 raise TypeError("SVM classification model expected") 607 615 608 616 model = [] 609 617 610 618 # Take the model up to nr_classes 611 619 libsvm_model = self.__wrapped.get_model() … … 615 623 else: 616 624 model.append(line.rstrip()) 617 618 model.append("nr_class %i" % len(class_var.values))625 nr_class = len(class_var.values) 626 model.append("nr_class %i" % nr_class) 619 627 model.append("total_sv %i" % reduce(add, [len(c) for c in coef])) 620 628 model.append("rho " + " ".join(str(r) for r in rho)) 621 model.append("label " + " ".join(str(i) for i in range( len(class_var.values))))629 model.append("label " + " ".join(str(i) for i in range(nr_class))) 622 630 # No probA and probB 623 631 624 632 model.append("nr_sv " + " ".join(str(len(c)) for c in coef)) 625 633 model.append("SV") 626 634 627 635 def instance_to_svm(inst): 628 636 values = [(i, float(inst[v])) \ … … 630 638 if not inst[v].is_special() and float(inst[v]) != 0.0] 631 639 return " ".join("%i:%f" % (i + 1, v) for i, v in values) 632 640 633 641 def sparse_instance_to_svm(inst): 634 642 non_meta = [] … … 642 650 metas.append("%i:%f" % (base  m_id, float(value))) 643 651 return " ".join(non_meta + metas) 644 652 645 653 if isinstance(self.__wrapped, _SVMClassifierSparse): 646 654 converter = sparse_instance_to_svm 647 655 else: 648 656 converter = instance_to_svm 649 657 650 658 if self.kernel_type == kernels.Custom: 651 659 SV = libsvm_model.split("SV\n", 1)[1] 652 660 # Get the sv indices (the last entry in the SV lines) 653 indices = [int(s.split(":")[1]) for s in SV.splitlines() if s.strip()] 654 655 # Reorder the indices 661 indices = [int(s.split(":")[1]) for s in SV.splitlines() \ 662 if s.strip()] 663 664 # Reorder the indices 656 665 label_map = self._get_libsvm_labels_map() 657 666 start = 0 … … 662 671 reordered_indices = [reordered_indices[i] for i in label_map] 663 672 indices = reduce(add, reordered_indices) 664 673 665 674 for (c, sv_i) in itertools.chain(*coef): 666 675 model.append("%f 0:%i" % (c, indices[sv_i])) 667 676 else: 668 677 for (c, sv_i) in itertools.chain(*coef): 669 model.append("%f %s" % (c, converter(self.support_vectors[sv_i]))) 670 678 model.append( 679 "%f %s" % (c, converter(self.support_vectors[sv_i])) 680 ) 681 671 682 model.append("") 672 683 return "\n".join(model) 673 684 674 685 675 686 SVMClassifier = Orange.utils.deprecated_members({ … … 678 689 "getModel" : "get_model", 679 690 }, wrap_methods=[])(SVMClassifier) 680 691 692 681 693 # Backwards compatibility (pickling) 682 694 SVMClassifierWrapper = SVMClassifier 695 683 696 684 697 class SVMLearnerSparse(SVMLearner): … … 699 712 if self.use_non_meta: 700 713 dc = preprocess.DomainContinuizer() 701 dc.class_treatment = preprocess.DomainContinuizer.Ignore702 dc.continuous_treatment = preprocess.DomainContinuizer.NormalizeBySpan703 dc.multinomial_treatment = preprocess.DomainContinuizer.NValues714 dc.class_treatment = dc.Ignore 715 dc.continuous_treatment = dc.NormalizeBySpan 716 dc.multinomial_treatment = dc.NValues 704 717 newdomain = dc(data) 705 718 data = data.translate(newdomain) 706 719 return data 707 720 721 708 722 class SVMLearnerEasy(SVMLearner): 709 710 723 """A class derived from :obj:`SVMLearner` that automatically 711 724 scales the data and performs parameter optimization using 712 725 :func:`SVMLearner.tune_parameters`. The procedure is similar to 713 726 that implemented in easy.py script from the LibSVM package. 714 727 715 728 """ 716 729 … … 719 732 :param folds: the number of folds to use in cross validation 720 733 :type folds: int 721 734 722 735 :param verbose: verbosity of the tuning procedure. 723 736 :type verbose: int 724 737 725 738 ``kwargs`` is passed to :class:`SVMLearner` 726 739 727 740 """ 728 741 SVMLearner.__init__(self, **kwargs) 729 742 self.folds = folds 730 743 self.verbose = verbose 731 744 732 745 self.learner = SVMLearner(**kwargs) 733 746 … … 740 753 newdomain = transformer(data) 741 754 newexamples = data.translate(newdomain) 742 #print newexamples[0] 743 params = {} 755 744 756 parameters = [] 745 self.learner.normalization = False ## Normalization already done757 self.learner.normalization = False # Normalization already done 746 758 747 759 if self.svm_type in [1, 4]: 748 numOfNuValues = 9749 760 if self.svm_type == SVMLearner.Nu_SVC: 750 761 max_nu = max(self.max_nu(newexamples)  1e7, 0.0) … … 756 767 parameters.append(("C", [2 ** a for a in range(5, 15, 2)])) 757 768 if self.kernel_type == 2: 758 parameters.append(("gamma", [2 ** a for a in range(5, 5, 2)] + [0])) 769 parameters.append( 770 ("gamma", [2 ** a for a in range(5, 5, 2)] + [0]) 771 ) 772 759 773 import orngWrap 760 774 tunedLearner = orngWrap.TuneMParameters(learner=self.learner, … … 763 777 764 778 return tunedLearner(newexamples, verbose=self.verbose) 779 765 780 766 781 class SVMLearnerSparseEasy(SVMLearnerEasy): … … 775 790 """ 776 791 792 777 793 class LinearSVMLearner(Orange.core.LinearLearner): 778 794 """Train a linear SVM model.""" … … 785 801 __new__ = _orange__new__(base=Orange.core.LinearLearner) 786 802 787 def __init__(self, solver_type=L2R_L2LOSS_DUAL, C=1.0, eps=0.01, 803 def __init__(self, solver_type=L2R_L2LOSS_DUAL, C=1.0, eps=0.01, 788 804 bias=1.0, normalization=True, **kwargs): 789 805 """ … … 791 807 ``L2R_L2LOSS_DUAL``, ``L2R_L2LOSS``, 792 808 ``L2R_L1LOSS_DUAL``, ``L1R_L2LOSS`` 793 794 The first part (``L2R`` or ``L1R``) is the regularization term 809 810 The first part (``L2R`` or ``L1R``) is the regularization term 795 811 on the weight vector (squared or absolute norm respectively), 796 812 the ``L1LOSS`` or ``L2LOSS`` indicate absolute or squared … … 798 814 solved in the dual space (for more information see the 799 815 documentation on `LIBLINEAR`_). 800 816 801 817 :param C: Regularization parameter (default 1.0) 802 818 :type C: float 803 819 804 820 :param eps: Stopping criteria (default 0.01) 805 821 :type eps: float 806 822 807 823 :param bias: If non negative then each instance is appended a constant 808 824 bias term (default 1.0). 809 825 810 826 :type bias: float 811 827 812 828 :param normalization: Normalize the input data prior to learning 813 829 (default True) 814 830 :type normalization: bool 815 831 816 832 Example 817 818 >>> linear_svm = LinearSVMLearner(solver_type=LinearSVMLearner.L1R_L2LOSS, 819 ... C=2.0) 833 834 >>> linear_svm = LinearSVMLearner( 835 ... solver_type=LinearSVMLearner.L1R_L2LOSS, 836 ... C=2.0) 820 837 ... 821 838 822 839 """ 823 840 self.solver_type = solver_type … … 831 848 if self.solver_type not in [self.L2R_L2LOSS_DUAL, self.L2R_L2LOSS, 832 849 self.L2R_L1LOSS_DUAL, self.L1R_L2LOSS]: 833 import warnings834 850 warnings.warn("""\ 835 Deprecated 'solver_type', use 851 Deprecated 'solver_type', use 836 852 'Orange.classification.logreg.LibLinearLogRegLearner' 837 853 to build a logistic regression model using LIBLINEAR. … … 856 872 LinearLearner = LinearSVMLearner 857 873 874 858 875 class MultiClassSVMLearner(Orange.core.LinearLearner): 859 876 """ Multiclass SVM (Crammer and Singer) from the `LIBLINEAR`_ library. 860 861 877 """ 862 878 __new__ = _orange__new__(base=Orange.core.LinearLearner) … … 866 882 """\ 867 883 :param C: Regularization parameter (default 1.0) 868 :type C: float 869 884 :type C: float 885 870 886 :param eps: Stopping criteria (default 0.01) 871 887 :type eps: float 872 888 873 889 :param bias: If non negative then each instance is appended a constant 874 890 bias term (default 1.0). 875 891 876 892 :type bias: float 877 893 878 894 :param normalization: Normalize the input data prior to learning 879 895 (default True) 880 896 :type normalization: bool 881 897 882 898 """ 883 899 self.C = C … … 907 923 #TODO: Unified way to get attr weights for linear SVMs. 908 924 925 909 926 def get_linear_svm_weights(classifier, sum=True): 910 927 """Extract attribute weights from the linear SVM classifier. 911 928 912 929 For multi class classification, the result depends on the argument 913 930 :obj:`sum`. If ``True`` (default) the function computes the … … 916 933 weights for each individual binary classifier (in the order of 917 934 [class1 vs class2, class1 vs class3 ... class2 vs class3 ...]). 918 935 919 936 """ 920 937 … … 932 949 933 950 if classifier.svm_type in [SVMLearner.C_SVC, SVMLearner.Nu_SVC]: 934 weights = [] 951 weights = [] 935 952 classes = classifier.class_var.values 936 953 for i in range(len(classes)  1): 937 954 for j in range(i + 1, len(classes)): 938 955 # Get the coef and rho values from the binary subclassifier 939 # Easier then using the full coef matrix (due to libsvm internal940 # class reordering)956 # Easier then using the full coef matrix (due to libsvm 957 # internal class reordering) 941 958 bin_classifier = classifier.get_binary_classifier(i, j) 942 959 n_sv0 = bin_classifier.n_SV[0] … … 971 988 update_weights(weights, attr, to_float(SV[attr]), coef) 972 989 973 return weights 990 return weights 974 991 975 992 getLinearSVMWeights = get_linear_svm_weights 993 976 994 977 995 def example_weighted_sum(example, weights): … … 983 1001 exampleWeightedSum = example_weighted_sum 984 1002 1003 985 1004 class ScoreSVMWeights(Orange.feature.scoring.Score): 986 1005 """ 987 1006 Score a feature using squared weights of a linear SVM model. 988 1007 989 1008 Example: 990 1009 991 1010 >>> table = Orange.data.Table("vehicle.tab") 992 1011 >>> score = Orange.classification.svm.ScoreSVMWeights() 993 >>> svm_scores = [(score(f, table), f) for f in table.domain.features] 1012 >>> svm_scores = [(score(f, table), f) for f in table.domain.features] 994 1013 >>> for feature_score, feature in sorted(svm_scores, reverse=True): 995 1014 ... print "%35s: %.3f" % (feature.name, feature_score) … … 1035 1054 """ 1036 1055 :param learner: Learner used for weight estimation 1037 (by default ``LinearSVMLearner(solver_type=L2R_L2LOSS_DUAL, C=1.0)`` 1056 (by default 1057 ``LinearSVMLearner(solver_type=L2R_L2LOSS_DUAL, C=1.0)`` 1038 1058 will be used for classification problems and 1039 1059 ``SVMLearner(svm_type=Epsilon_SVR, kernel_type=Linear, C=1.0, p=0.25)`` 1040 for regression problems .1041 1042 :type learner: Orange.core.LinearLearner 1043 1060 for regression problems). 1061 1062 :type learner: Orange.core.LinearLearner 1063 1044 1064 """ 1045 1065 self.learner = learner … … 1056 1076 learner = self.learner 1057 1077 elif isinstance(data.domain.class_var, variable.Discrete): 1058 learner = LinearSVMLearner(solver_type= 1059 LinearSVMLearner.L2R_L2LOSS_DUAL, 1060 C=1.0) 1078 learner = LinearSVMLearner( 1079 solver_type=LinearSVMLearner.L2R_L2LOSS_DUAL, 1080 C=1.0) 1081 1061 1082 elif isinstance(data.domain.class_var, variable.Continuous): 1062 1083 learner = SVMLearner(svm_type=SVMLearner.Epsilon_SVR, … … 1080 1101 1081 1102 def _extract_weights(self, classifier, original_features): 1082 """Extract weights from a svm classifer (``SVMClassifier`` or a 1103 """Extract weights from a svm classifer (``SVMClassifier`` or a 1083 1104 ``LinearLearner`` instance). 1084 1105 1085 1106 """ 1086 1107 import numpy as np … … 1089 1110 if isinstance(classifier.class_var, variable.Continuous): 1090 1111 # The weights are in the the original non squared form 1091 weights = dict((f, w ** 2) for f, w in weights.items()) 1112 weights = dict((f, w ** 2) for f, w in weights.items()) 1092 1113 elif isinstance(classifier, Orange.core.LinearClassifier): 1093 1114 weights = np.array(classifier.weights) … … 1106 1127 elif f not in weights and f in sources: 1107 1128 dummys = sources[f] 1108 # Use averege weight 1129 # Use averege weight 1109 1130 source_weights[f] = np.average([weights[d] for d in dummys]) 1110 1131 else: … … 1117 1138 variables (``source_variable`` or ``get_value_from.variable`` members) 1118 1139 back to the variables in ``vars``. 1119 1140 1120 1141 """ 1121 1142 source = defaultdict(list) 1122 1143 for var in vars: 1123 svar = None1124 1144 if var.source_variable: 1125 1145 source[var.source_variable].append(var) … … 1127 1147 source[var.get_value_from.variable].append(var) 1128 1148 elif isinstance(var.get_value_from, Orange.core.ImputeClassifier): 1129 source[var.get_value_from.classifier_from_var.variable].append(var) 1149 imputer = var.get_value_from.classifier_from_var 1150 source[imputer.variable].append(var) 1130 1151 else: 1131 1152 source[var].append(var) … … 1134 1155 MeasureAttribute_SVMWeights = ScoreSVMWeights 1135 1156 1157 1136 1158 class RFE(object): 1137 1159 1138 1160 """Iterative feature elimination based on weights computed by 1139 1161 linear SVM. 1140 1162 1141 1163 Example:: 1142 1164 1143 1165 >>> table = Orange.data.Table("promoters.tab") 1144 1166 >>> svm_l = Orange.classification.svm.SVMLearner( 1145 ... kernel_type=Orange.classification.svm.kernels.Linear) 1146 ... 1167 ... kernel_type=Orange.classification.svm.kernels.Linear) 1168 ... 1147 1169 >>> rfe = Orange.classification.svm.RFE(learner=svm_l) 1148 1170 >>> data_with_subset_of_features = rfe(table, 10) 1149 1171 >>> data_with_subset_of_features.domain 1150 1172 [p45, p36, p35, p34, p33, p31, p18, p12, p10, p04, y] 1151 1173 1152 1174 """ 1153 1175 1154 1176 def __init__(self, learner=None): 1155 1177 """ 1156 :param learner: A linear svm learner for use with 1178 :param learner: A linear svm learner for use with 1157 1179 :class:`ScoreSVMWeights`. 1158 1180 1159 1181 """ 1160 1182 self.learner = learner 1161 1183 1162 @Orange.utils.deprecated_keywords({"progressCallback": "progress_callback", "stopAt": "stop_at" }) 1184 @Orange.utils.deprecated_keywords({"progressCallback": "progress_callback", 1185 "stopAt": "stop_at"}) 1163 1186 def get_attr_scores(self, data, stop_at=0, progress_callback=None): 1164 1187 """Return a dictionary mapping attributes to scores. 1165 1188 A score is a step number at which the attribute 1166 1189 was removed from the recursive evaluation. 1167 1190 1168 1191 """ 1169 1192 iter = 1 … … 1186 1209 return attr_scores 1187 1210 1188 @Orange.utils.deprecated_keywords({"numSelected": "num_selected", "progressCallback": "progress_callback"}) 1211 @Orange.utils.deprecated_keywords( 1212 {"numSelected": "num_selected", 1213 "progressCallback": "progress_callback"}) 1189 1214 def __call__(self, data, num_selected=20, progress_callback=None): 1190 """Return a new dataset with only `num_selected` best scoring attributes 1191 1215 """Return a new dataset with only `num_selected` best scoring 1216 attributes. 1217 1192 1218 :param data: Data 1193 1219 :type data: Orange.data.Table 1194 1220 1195 1221 :param num_selected: number of features to preserve 1196 1222 :type num_selected: int 1197 1223 1198 1224 """ 1199 1225 scores = self.get_attr_scores(data, progress_callback=progress_callback) … … 1207 1233 return data 1208 1234 1235 1209 1236 RFE = Orange.utils.deprecated_members({ 1210 1237 "getAttrScores": "get_attr_scores"}, 1211 1238 wrap_methods=["get_attr_scores", "__call__"])(RFE) 1212 1239 1240 1213 1241 def example_table_to_svm_format(table, file): 1214 1242 warnings.warn("Deprecated. Use table_to_svm_format", DeprecationWarning) … … 1217 1245 exampleTableToSVMFormat = example_table_to_svm_format 1218 1246 1247 1219 1248 def table_to_svm_format(data, file): 1220 1249 """Save :obj:`Orange.data.Table` to a format used by LibSVM. 1221 1250 1222 1251 :param data: Data 1223 1252 :type data: Orange.data.Table 1224 1253 :param file: file pointer 1225 1254 :type file: file 1226 1255 1227 1256 """ 1228 1257
Note: See TracChangeset
for help on using the changeset viewer.