Пример #1
0
 def __init__(self):
     self.mc = MultiClassifier()
     self.labelset = set()
     self.c = 1.0
     self.j = None
     self.tmp = "/tmp/"
     self.binary = "svm_perf_learn"
Пример #2
0
Файл: svm.py Проект: alad/Mekano
class SVMMultiClassifier:
    def __init__(self):
        self.mc = MultiClassifier()
        self.labelset = set()
        self.c = 1.0
        self.j = None
        self.tmp = "/tmp/"
        self.binary = "svm_perf_learn"
        
    def train(self, ds):
        bds = ds.binarize()
        positions = None
        print "SVMMultiClassifier: Training with %d docs, %d labels" % (len(ds.docs), len(bds))
        for label in bds:
            if positions is None:
                fout = tempfile.NamedTemporaryFile(suffix='svm', dir=self.tmp)
                positions = bds[label].toSVM(fout)
            else:
                bds[label].toSVMSubsequent(fout, positions)
            fout.file.flush()
            modelfilename = "%s-%s.model" % (fout.name, label)
            _run("%s %s %s %s > /dev/null 2>&1" % (self.binary, _svm_params(self), fout.name, modelfilename))
            self.mc.add(label, SVMClassifier(modelfilename))
            os.remove(modelfilename)
        fout.close()
        self.labelset = set(bds)

    def __repr__(self):
        return "<SVMMultiClassfier: %d labels>" % len(self.labelset)

    def score(self, av):
        return self.mc.score(av)
Пример #3
0
class SVMMultiClassifier:
    def __init__(self):
        self.mc = MultiClassifier()
        self.labelset = set()
        self.c = 1.0
        self.j = None
        self.tmp = "/tmp/"
        self.binary = "svm_perf_learn"

    def train(self, ds):
        bds = ds.binarize()
        positions = None
        print "SVMMultiClassifier: Training with %d docs, %d labels" % (len(
            ds.docs), len(bds))
        for label in bds:
            if positions is None:
                fout = tempfile.NamedTemporaryFile(suffix='svm', dir=self.tmp)
                positions = bds[label].toSVM(fout)
            else:
                bds[label].toSVMSubsequent(fout, positions)
            fout.file.flush()
            modelfilename = "%s-%s.model" % (fout.name, label)
            _run("%s %s %s %s > /dev/null 2>&1" %
                 (self.binary, _svm_params(self), fout.name, modelfilename))
            self.mc.add(label, SVMClassifier(modelfilename))
            os.remove(modelfilename)
        fout.close()
        self.labelset = set(bds)

    def __repr__(self):
        return "<SVMMultiClassfier: %d labels>" % len(self.labelset)

    def score(self, av):
        return self.mc.score(av)
Пример #4
0
Файл: svm.py Проект: alad/Mekano
 def __init__(self):
     self.mc = MultiClassifier()
     self.labelset = set()
     self.c = 1.0
     self.j = None
     self.tmp = "/tmp/"
     self.binary = "svm_perf_learn"