Example #1
0
                        (Orange.data.Table(newdomain, data), weight_id),
                        indices)

                    newStat = self.stat(res)[0]
                    newStats = [
                        self.stat(x)[0] for x in
                        Orange.evaluation.scoring.split_by_iterations(res)
                    ]
                    print "+", newStat, newdomain

                    ## If stat has increased (ie newStat is better than bestStat)
                    if cmp(newStat,
                           bestStat) == self.statsign and statc.wilcoxont(
                               oldStats, newStats)[1] < self.add_threshold:
                        bestStat, bestStats, bestAttr = newStat, newStats, attr
            if bestAttr:
                domain = Orange.data.Domain(domain.attributes + [bestAttr],
                                            classVar)
                oldStat, oldStats = bestStat, bestStats
                stop = False
                print "added", bestAttr.name

        return self.learner(Orange.data.Table(domain, data), weight_id)


StepwiseLearner = deprecated_members(
    {
        "removeThreshold": "remove_threshold",
        "addThreshold": "add_threshold"
    }, )(StepwiseLearner)
Example #2
0
            j = i + 1 if self.intercept else i
            dict_model[var.name] = (coefficients[j], \
                                   std_error[j],\
                                   t_scores[j],\
                                   p_vals[j])
        
        return LinearRegression(domain.class_var, domain, coefficients, F,
                 std_error=std_error, t_scores=t_scores, p_vals=p_vals, dict_model=dict_model,
                 fitted=fitted, residuals=residuals, m=m, n=n, mu_y=mu_y,
                 r2=r2, r2adj=r2adj, sst=sst, sse=sse, ssr=ssr,
                 std_coefficients=std_coefficients, intercept=self.intercept)

deprecated_members({"ridgeLambda": "ridge_lambda",
                    "computeStats": "compute_stats",
                    "useVars": "use_vars",
                    "addSig": "add_sig",
                    "removeSig": "remove_sig",
                    }
                   , ["__init__"],
                   in_place=True)(LinearRegressionLearner)

class LinearRegression(Orange.classification.Classifier):

    """Linear regression predicts value of the response variable
    based on the values of independent variables.

    .. attribute:: F
    
        F-statistics of the model.

    .. attribute:: coefficients
Example #3
0
                domain = Orange.data.Domain(filter(lambda x: x!=bestAttr, domain.attributes), classVar)
                oldStat, oldStats = bestStat, bestStats
                stop = False
                print "removed", bestAttr.name

        bestStat, bestAttr = oldStat, None
        for attr in data.domain.attributes:
            if not attr in domain.attributes:
                newdomain = Orange.data.Domain(domain.attributes + [attr], classVar)
                res = Orange.evaluation.testing.test_with_indices([self.learner], (Orange.data.Table(newdomain, data), weight_id), indices)
                
                newStat = self.stat(res)[0]
                newStats = [self.stat(x)[0] for x in Orange.evaluation.scoring.split_by_iterations(res)] 
                print "+", newStat, newdomain

                ## If stat has increased (ie newStat is better than bestStat)
                if cmp(newStat, bestStat) == self.statsign and statc.wilcoxont(oldStats, newStats)[1] < self.add_threshold:
                    bestStat, bestStats, bestAttr = newStat, newStats, attr
        if bestAttr:
            domain = Orange.data.Domain(domain.attributes + [bestAttr], classVar)
            oldStat, oldStats = bestStat, bestStats
            stop = False
            print "added", bestAttr.name

    return self.learner(Orange.data.Table(domain, data), weight_id)

StepwiseLearner = deprecated_members(
                    {"removeThreshold": "remove_threshold",
                     "addThreshold": "add_threshold"},
                    )(StepwiseLearner)
Example #4
0
            d = nd
        # normalizing multiplier
        sum = 0.0
        for i in d:
            sum += i[2]*i[2]*i[1]
        f = numpy.sqrt(distnorm/numpy.max(sum,1e-6))
        # transform O
        k = 0
        for i in d:
            for j in range(i[1]):
                (ii,jj) = o[k][1]
                self.distances[ii,jj] = f*i[2]
                k += 1
        assert(len(o) == k)
        self.freshD = 0
        return effect
    
MDS = deprecated_members({"projectedDistances": "projected_distances",
                     "originalDistances": "original_distances",
                     "avgStress": "avg_stress",
                     "progressCallback": "progress_callback",
                     "getStress": "calc_stress",
                     "get_stress": "calc_stress",
                     "calcStress": "calc_stress",
                     "getDistance": "calc_distance",
                     "get_distance": "calc_distance",
                     "calcDistance": "calc_distance",
                     "Torgerson": "torgerson",
                     "SMACOFstep": "smacof_step",
                     "LSMT": "lsmt"})(MDS)
Example #5
0
            dict_model[var.name] = (coefficients[i], std_errors_fixed_t[i],
                                    p_vals[i])

        return LassoRegression(domain=domain,
                               class_var=domain.class_var,
                               coef0=coef0,
                               coefficients=coefficients,
                               std_errors_fixed_t=std_errors_fixed_t,
                               p_vals=p_vals,
                               dict_model=dict_model,
                               mu_x=mu_x)


deprecated_members({
    "nBoot": "n_boot",
    "nPerm": "n_perm"
},
                   wrap_methods=["__init__"],
                   in_place=True)(LassoRegressionLearner)


class LassoRegression(Orange.classification.Classifier):
    """Lasso regression predicts value of the response variable
    based on the values of independent variables.

    .. attribute:: coef0

        Intercept (sample mean of the response variable).    

    .. attribute:: coefficients

        Regression coefficients, sotred in list. 
Example #6
0
        if True or self.deflation_mode == "regression":
            # Estimate regression coefficient
            # Y = TQ' + E = X W(P'W)^-1Q' + E = XB + E
            # => B = W*Q' (p x q)
            coefs = dot(xRotations, Q.T)
            coefs = 1. / sigmaX.reshape((p, 1)) * \
                    coefs * sigmaY
        
        return {"mu_x": muX, "mu_y": muY, "sigma_x": sigmaX,
                "sigma_y": sigmaY, "T": T, "U":U, "W":U, 
                "C": C, "P":P, "Q":Q, "x_rotations": xRotations,
                "y_rotations": yRotations, "coefs": coefs}

deprecated_members({"nComp": "n_comp",
                    "deflationMode": "deflation_mode",
                    "maxIter": "max_iter"},
                   wrap_methods=["__init__"],
                   in_place=True)(PLSRegressionLearner)

class PLSRegression(Orange.classification.Classifier):
    """ PLSRegression predicts value of the response variables
    based on the values of independent variables.
    
    Basic notations:
    n - number of data instances
    p - number of independent variables
    q - number of reponse variables

    .. attribute:: T
    
        A n x n_comp numpy array of x-scores
Example #7
0
        if isinstance(aclass, (list, tuple)):
            self.classes[i] = aclass
            self.probabilities[i] = aprob
        elif type(aclass.value) == float:
            self.classes[i] = float(aclass)
            self.probabilities[i] = aprob
        else:
            self.classes[i] = int(aclass)
            self.probabilities[i] = list(aprob)

    def __repr__(self):
        return str(self.__dict__)


TestedExample = deprecated_members({
    "iterationNumber": "iteration_number",
    "actualClass": "actual_class"
})(TestedExample)


class ExperimentResults(object):
    """
    ``ExperimentResults`` stores results of one or more repetitions of
    some test (cross validation, repeated sampling...) under the same
    circumstances.

    :var results: A list of instances of :obj:`TestedExample`, one for each example in the dataset.
    :var classifiers: A list of classifiers, one element for each repetition (eg. fold). Each element is a list
      of classifiers, one for each learner. This field is used only if storing is enabled by ``storeClassifiers=1``.
    :var number_of_iterations: Number of iterations. This can be the number of folds (in cross validation)
      or the number of repetitions of some test. :obj:`TestedExample`'s attribute ``iteration_number`` should
      be in range ``[0, number_of_iterations-1]``.
Example #8
0
                setattr(self, name, value)
            self.__init__(**argkw)
            return self.__call__(data, weight_id)
        else:
            return self

    def findobj(self, name):
        import string
        names = string.split(name, ".")
        lastobj = self.object
        for i in names[:-1]:
            lastobj = getattr(lastobj, i)
        return lastobj, names[-1]

TuneParameters = deprecated_members(
    {"returnWhat": "return_what",
     "object": "learner"},
    )(TuneParameters)


class Tune1Parameter(TuneParameters):

    """Class :obj:`Orange.optimization.Tune1Parameter` tunes a single parameter.
    
    .. attribute:: parameter
    
        The name of the parameter (or a list of names, if the same parameter is
        stored at multiple places - see the examples) to be tuned.
    
    .. attribute:: values
    
        A list of parameter's values to be tried.
Example #9
0
            return self.__call__(data, weight_id)
        else:
            return self

    def findobj(self, name):
        import string
        names = string.split(name, ".")
        lastobj = self.object
        for i in names[:-1]:
            lastobj = getattr(lastobj, i)
        return lastobj, names[-1]


TuneParameters = deprecated_members(
    {
        "returnWhat": "return_what",
        "object": "learner"
    }, )(TuneParameters)


class Tune1Parameter(TuneParameters):
    """Class :obj:`Orange.optimization.Tune1Parameter` tunes a single parameter.
    
    .. attribute:: parameter
    
        The name of the parameter (or a list of names, if the same parameter is
        stored at multiple places - see the examples) to be tuned.
    
    .. attribute:: values
    
        A list of parameter's values to be tried.
Example #10
0
            attributes = data.domain.features[:]
            if lr in attributes:
                attributes.remove(lr)
            else:
                attributes.remove(lr.getValueFrom.variable)
            new_domain = Orange.data.Domain(attributes, 
                data.domain.class_var)
            new_domain.addmetas(data.domain.getmetas())
            data = data.select(new_domain)
            lr = learner.fit_model(data, weight)
        return lr

LogRegLearner = deprecated_members({"removeSingular": "remove_singular",
                                    "weightID": "weight_id",
                                    "stepwiseLR": "stepwise_lr",
                                    "addCrit": "add_crit",
                                    "deleteCrit": "delete_crit",
                                    "numFeatures": "num_features",
                                    "removeMissing": "remove_missing"
                                    })(LogRegLearner)

class UnivariateLogRegLearner(Orange.classification.Learner):
    def __new__(cls, data=None, **argkw):
        self = Orange.classification.Learner.__new__(cls, **argkw)
        if data:
            self.__init__(**argkw)
            return self.__call__(data)
        else:
            return self

    def __init__(self, **kwds):
        self.__dict__.update(kwds)
Example #11
0
        return self.best

    def winner_index(self):
        """Return the index of the optimal object within the sequence of
        the candidates.
        
        :rtype: int
        """
        if self.best is not None:
            return self.best_index
        else:
            return None

BestOnTheFly = deprecated_members({"callCompareOn1st": "call_compare_on_1st",
                                   "winnerIndex": "winner_index",
                                   "randomGenerator": "random_generator",
                                   "bestIndex": "best_index"
                                   },
                                   wrap_methods=["__init__"])(BestOnTheFly)


@deprecated_keywords({"callCompareOn1st": "call_compare_on_1st"})
def select_best(x, compare=cmp, seed = 0, call_compare_on_1st = False):
    """Return the optimal object from list x. The function is used if the candidates
    are already in the list, so using the more complicated :obj:`BestOnTheFly` directly is
    not needed.

    To demonstrate the use of :obj:`BestOnTheFly` see the implementation of
    :obj:`selectBest`::
    
      def selectBest(x, compare=cmp, seed = 0, call_compare_on_1st = False):
          bs=BestOnTheFly(compare, seed, call_compare_on_1st)
Example #12
0
        sum = 0.0
        for i in d:
            sum += i[2] * i[2] * i[1]
        f = numpy.sqrt(distnorm / numpy.max(sum, 1e-6))
        # transform O
        k = 0
        for i in d:
            for j in range(i[1]):
                (ii, jj) = o[k][1]
                self.distances[ii, jj] = f * i[2]
                k += 1
        assert (len(o) == k)
        self.freshD = 0
        return effect

MDS = deprecated_members({
    "projectedDistances": "projected_distances",
    "originalDistances": "original_distances",
    "avgStress": "avg_stress",
    "progressCallback": "progress_callback",
    "getStress": "calc_stress",
    "get_stress": "calc_stress",
    "calcStress": "calc_stress",
    "getDistance": "calc_distance",
    "get_distance": "calc_distance",
    "calcDistance": "calc_distance",
    "Torgerson": "torgerson",
    "SMACOFstep": "smacof_step",
    "LSMT": "lsmt"
})(MDS)
Example #13
0
            attributes = data.domain.features[:]
            if lr in attributes:
                attributes.remove(lr)
            else:
                attributes.remove(lr.getValueFrom.variable)
            new_domain = Orange.data.Domain(attributes, data.domain.class_var)
            new_domain.addmetas(data.domain.getmetas())
            data = data.select(new_domain)
            lr = learner.fit_model(data, weight)
        return lr

LogRegLearner = deprecated_members({
    "removeSingular": "remove_singular",
    "weightID": "weight_id",
    "stepwiseLR": "stepwise_lr",
    "addCrit": "add_crit",
    "deleteCrit": "delete_crit",
    "numFeatures": "num_features",
    "removeMissing": "remove_missing"
})(LogRegLearner)


class UnivariateLogRegLearner(Orange.classification.Learner):
    def __new__(cls, data=None, **argkw):
        self = Orange.classification.Learner.__new__(cls, **argkw)
        if data:
            self.__init__(**argkw)
            return self.__call__(data)
        else:
            return self
Example #14
0
    def winner_index(self):
        """Return the index of the optimal object within the sequence of
        the candidates.
        
        :rtype: int
        """
        if self.best is not None:
            return self.best_index
        else:
            return None


BestOnTheFly = deprecated_members(
    {
        "callCompareOn1st": "call_compare_on_1st",
        "winnerIndex": "winner_index",
        "randomGenerator": "random_generator",
        "bestIndex": "best_index"
    },
    wrap_methods=["__init__"])(BestOnTheFly)


@deprecated_keywords({"callCompareOn1st": "call_compare_on_1st"})
def select_best(x, compare=cmp, seed=0, call_compare_on_1st=False):
    """Return the optimal object from list x. The function is used if the candidates
    are already in the list, so using the more complicated :obj:`BestOnTheFly` directly is
    not needed.

    To demonstrate the use of :obj:`BestOnTheFly` see the implementation of
    :obj:`selectBest`::
    
      def selectBest(x, compare=cmp, seed = 0, call_compare_on_1st = False):
Example #15
0
                                n=n,
                                mu_y=mu_y,
                                r2=r2,
                                r2adj=r2adj,
                                sst=sst,
                                sse=sse,
                                ssr=ssr,
                                std_coefficients=std_coefficients,
                                intercept=self.intercept)


deprecated_members(
    {
        "ridgeLambda": "ridge_lambda",
        "computeStats": "compute_stats",
        "useVars": "use_vars",
        "addSig": "add_sig",
        "removeSig": "remove_sig",
    }, ["__init__"],
    in_place=True)(LinearRegressionLearner)


class LinearRegression(Orange.classification.Classifier):
    """Linear regression predicts value of the response variable
    based on the values of independent variables.

    .. attribute:: F
    
        F-statistics of the model.

    .. attribute:: coefficients
Example #16
0
        # dictionary of regression coefficients with standard errors
        # and p-values
        dict_model = {}
        for i, var in enumerate(domain.attributes):
            dict_model[var.name] = (coefficients[i], std_errors_fixed_t[i], p_vals[i])

        return LassoRegression(domain=domain, class_var=domain.class_var,
                               coef0=coef0, coefficients=coefficients,
                               std_errors_fixed_t=std_errors_fixed_t,
                               p_vals=p_vals,
                               dict_model=dict_model,
                               mu_x=mu_x)

deprecated_members({"nBoot": "n_boot",
                    "nPerm": "n_perm"},
                   wrap_methods=["__init__"],
                   in_place=True)(LassoRegressionLearner)

class LassoRegression(Orange.classification.Classifier):
    """Lasso regression predicts value of the response variable
    based on the values of independent variables.

    .. attribute:: coef0

        Intercept (sample mean of the response variable).    

    .. attribute:: coefficients

        Regression coefficients, sotred in list. 

    .. attribute:: std_errors_fixed_t