Example #1
0
 def trainTest(self,testSplit,**kw):
     idLab = self.idLab
     spDir = self.getSplitDirName(testSplit)
     makedir(spDir)
     idLabRec = idLab.getRecords()
     spIdLab = idLabRec.copy()
     spIdLab["split"] = 1
     spIdLab["split"][idLabRec["split"]==testSplit] = 2
     spIdLabFile = pjoin(spDir,"idlab.pkl")
     saveIdLabelRecords(records=spIdLab,fileName=spIdLabFile)
     spClOpt = copy(self.clOpt)
     spClOpt.labels = [spIdLabFile]
     spClOpt.predFile = pjoin(spDir,"pred.pkl")
     spClOpt.perfFile = pjoin(spDir,"perf.pkl")
     spClOpt.mode = "trainScatter"
     spClOpt.runMode = self.opt.runMode
     spClOpt.cwd = spDir
     spOptFile = self.getSplitOptFileName(testSplit)
     spApp = ClassifierApp(opt=spClOpt)
     spClOpt = spApp.getOpt() #get the missing options filled with defaults
     #that just saves a copy for us - App will create its own when it 
     #submits a batch job (unique and slightly modified)
     dumpObj(spClOpt,spOptFile)
     kw = kw.copy()
     jobs = spApp.run(**kw)
     spClOpt.mode = "test"
     spApp = ClassifierApp(opt=spClOpt)
     kw["depend"] = jobs
     jobs = spApp.run(**kw)
     return jobs
Example #2
0
    def run(self, **kw):
        from MGT.ClassifierApp import ClassifierApp

        opt = self.opt
        opt.cwd = self.path  # in case we moved it after __init__()
        opt.predFile = pjoin(opt.cwd, "pred.pkl")
        jobs = []
        opt.mode = "predict"
        app = ClassifierApp(opt=opt)
        opt = app.getOpt()  # get the missing options filled with defaults
        jobs = app.run(**kw)
        self.save()
        return jobs
Example #3
0
    def run(self, **kw):
        from MGT.ClassifierApp import ClassifierApp

        opt = self.opt
        opt.cwd = self.path  # in case we moved it after __init__()
        jobs = []
        opt.mode = "trainScatter"
        app = ClassifierApp(opt=opt)
        opt = app.getOpt()  # get the missing options filled with defaults
        # we need to clean up the models directory otherwise we run a danger
        # of picking up old models that are not trained in this session
        rmrf(self.getFilePath(opt.modelRoot))
        return app.run(**kw)
Example #4
0
def makeClOpt(testDataDir):
    o,a = ClassifierApp.defaultOptions()
    o.C = 0.03
    o.kernel = "lin" #"rbf"
    origFeat = [pjoin(testDataDir,"usps-train.pkl"),pjoin(testDataDir,"usps-test.pkl")]
    o.inFeat = origFeat
    #o.inFeat = [pjoin(testDataDir,"usps.libsvm.pca")]
    o.labels = [ lf+".idlab" for lf in origFeat ]
    return o
Example #5
0
def makeClOpt(testDataDir):
    o,a = ClassifierApp.defaultOptions()
    o.method = "svm" #"svm" #"smlr"
    o.C = 0.001
    o.kernel = "rbf" #"rbf" "lin"
    o.inFeatFormat = "pkl" #"txt" #"pkl"
    if o.inFeatFormat == "txt":
        ext = ".libsvm"
    elif o.inFeatFormat == "pkl":
        ext = ".pkl"
    else:
        raise ValueError(o.inFeatFormat)
    origFeat = [pjoin(testDataDir,"usps-train"+ext),pjoin(testDataDir,"usps-test"+ext)]
    o.inFeat = origFeat
    #o.inFeat = [pjoin(testDataDir,"usps.libsvm.pca")]
    o.labels = [ lf+".idlab" for lf in origFeat ]
    o.balanceTrainCounts=-1
    return o
Example #6
0
    def run(self, **kw):
        from MGT.ClassifierApp import ClassifierApp

        opt = self.opt
        opt.cwd = self.path  # in case we moved it after __init__()
        opt.predFile = pjoin(opt.cwd, "pred.pkl")
        opt.perfFile = pjoin(opt.cwd, "perf.pkl")
        jobs = []
        opt.mode = "trainScatter"
        app = ClassifierApp(opt=opt)
        opt = app.getOpt()  # get the missing options filled with defaults
        # we need to clean up the models directory otherwise we run a danger
        # of picking up old models that are not trained in this session
        rmrf(self.getFilePath(opt.modelRoot))
        jobs = app.run(**kw)
        opt.mode = "test"
        app = ClassifierApp(opt=opt)
        opt = app.getOpt()  # get the missing options filled with defaults
        self.save()
        kw = kw.copy()
        kw["depend"] = jobs
        jobs = app.run(**kw)
        return jobs
def makeClOpt():
    o,a = ClassifierApp.defaultOptions()
    o.C = 0.03
    o.inFeat = [os.path.abspath("usps-train.libsvm"),os.path.abspath("usps-test.libsvm")]
    o.labels = [ lf+".idlab" for lf in o.inFeat ]
    return o
Example #8
0
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
#
#   See COPYING file distributed along with the MGTAXA package for the
#   copyright and license terms.
#
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##


"""Shell scripting interface to supervised classifiers."""
from MGT.ClassifierApp import ClassifierApp
app = ClassifierApp()
app.run()

Example #9
0
    else:
        raise ValueError(o.inFeatFormat)
    origFeat = [pjoin(testDataDir,"usps-train"+ext),pjoin(testDataDir,"usps-test"+ext)]
    o.inFeat = origFeat
    #o.inFeat = [pjoin(testDataDir,"usps.libsvm.pca")]
    o.labels = [ lf+".idlab" for lf in origFeat ]
    o.balanceTrainCounts=-1
    return o

testDataDir = pjoin(options.testDataDir,"usps")

workDir = pjoin(os.getcwd(),"test_ClassifierApp.tmpdir")
rmdir(workDir)
makedir(workDir)
os.chdir(workDir)

clOpt = makeClOpt(testDataDir)
clOpt.numTrainJobs = 1 #6
clOpt.MEM = 500
clOpt.LENGTH = "fast"
clOpt.mode = "trainScatter"
clOpt.runMode = "inproc" #"inproc" #"batchDep"
print clOpt
app = ClassifierApp(opt=clOpt)
jobs = app.run(dryRun=False)
clOpt.mode = "test"
clOpt.perfFile = "perf.pkl"
app = ClassifierApp(opt=clOpt)
jobs = app.run(dryRun=False,depend=jobs)