Source

orange / Orange / orng / orngMultivariatePrediction.py

import orange
import orngRegression

class MultiClassPredictionLearner(object):
    """(self, data, y, x=None)"""
    def __new__(self, data=None, name='multivar pred', **kwds):
        learner = object.__new__(self)
        if data:
            learner.__init__(name) # force init
            return learner(data)
        else:
            return learner  # invokes the __init__

    def __init__(self, name='multivar pred', baseLearner=orngRegression.LinearRegressionLearner):
        self.name = name
        self.baseLearner = baseLearner
                
    def __call__(self, data, y, x=None, weight=None):
        if y == None:
            try:
                y = [data.domain.classVar]
            except:
                import warnings
                warnings.warn("multi-class learner requires either specification of response variables or a data domain with a class")
                return None
        if x == None:
            print y
            x = [v for v in data.domain.variables if v not in y]

        models = []
        for a in y:
            newDomain = orange.Domain(x, a)
            newData = orange.ExampleTable(newDomain, data)
            models.append(baseLearner(newData))
        return MultiClassPrediction(x=x, y=y, models=models)
       
class MultiClassPrediction:
    def __init__(self, **kwds):
        self.__dict__.update(kwds)

    def __call__(self, example):
        return [m(example) for m in self.models]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.