Exemplo n.º 1
0
    def get_attr_scores(self, data, stop_at=0, progress_callback=None):
        """Return a dictionary mapping attributes to scores.
        A score is a step number at which the attribute
        was removed from the recursive evaluation.
        
        """
        iter = 1
        attrs = data.domain.attributes
        attrScores = {}

        while len(attrs) > stop_at:
            weights = get_linear_svm_weights(self.learner(data), sum=False)
            if progress_callback:
                progress_callback(100. * iter / (len(attrs) - stop_at))
            score = dict.fromkeys(attrs, 0)
            for w in weights:
                for attr, wAttr in w.items():
                    score[attr] += wAttr ** 2
            score = score.items()
            score.sort(lambda a, b:cmp(a[1], b[1]))
            numToRemove = max(int(len(attrs) * 1.0 / (iter + 1)), 1)
            for attr, s in  score[:numToRemove]:
                attrScores[attr] = len(attrScores)
            attrs = [attr for attr, s in score[numToRemove:]]
            if attrs:
                data = data.select(attrs + [data.domain.classVar])
            iter += 1
        return attrScores
Exemplo n.º 2
0
def score_smiles_variables(data, candidates=None, max_sample=20):
    if candidates is None:
        candidates = data.domain.variables + data.domain.getmetas().values()
        candidates = filter(
            lambda v: isinstance(v, (Orange.feature.Discrete, Orange.feature.
                                     String)), candidates)

    if len(data) > max_sample:
        indices = Orange.data.sample.SubsetIndices2(data, max_sample)
        data = data.select(indices, 0)

    scored = [(var, sum([is_valid_smiles(str(e[var])) for e in data]))
              for var in candidates]
    return scored
def score_smiles_variables(data, candidates=None, max_sample=20):
    if candidates is None:
        candidates = data.domain.variables + data.domain.getmetas().values()
        candidates = filter(lambda v: isinstance(v, (Orange.feature.Discrete,
                                                     Orange.feature.String)),
                            candidates)

    if len(data) > max_sample:
        indices = Orange.data.sample.SubsetIndices2(data, max_sample)
        data = data.select(indices, 0)

    scored = [(var, sum([is_valid_smiles(str(e[var])) for e in data]))
              for var in candidates]
    return scored
Exemplo n.º 4
0
    def get_attr_scores(self, data, stop_at=0, progress_callback=None):
        """Return a dictionary mapping attributes to scores.
        A score is a step number at which the attribute
        was removed from the recursive evaluation.

        """
        iter = 1
        attrs = data.domain.attributes
        attr_scores = {}
        scorer = ScoreSVMWeights(learner=self.learner)

        while len(attrs) > stop_at:
            scores = [(scorer(attr, data), attr) for attr in attrs]
            if progress_callback:
                progress_callback(100. * iter / (len(attrs) - stop_at))
            scores = sorted(scores)
            num_to_remove = max(int(len(attrs) * 1.0 / (iter + 1)), 1)
            for s, attr in  scores[:num_to_remove]:
                attr_scores[attr] = len(attr_scores)
            attrs = [attr for s, attr in scores[num_to_remove:]]
            if attrs:
                data = data.select(attrs + [data.domain.class_var])
            iter += 1
        return attr_scores