示例#1
0
def crossValidation():
    print('reading cross validation data...')
    config.swLog.write('reading cross validation data...\n')
    XList = []
    XXList = []
    loadDataForCV(XList, XXList)
    for r in config.regList:
        config.swLog.write('\ncross validation. r={}\n'.format(r))
        print('\ncross validation. r={}'.format(r))
        if config.rawResWrite:
            config.swResRaw.write('% cross validation. r={}'.format(r))
        for i in range(config.nCV):
            config.swLog.write('\n#validation={}\n'.format(i + 1))
            print('\n#validation={}'.format(i + 1))
            if config.rawResWrite:
                config.swResRaw.write('\n#validation={}\n'.format(i + 1))
            config.reg = r
            Xi = XList[i]
            if config.runMode.find('rich') >= 0:
                tb = toolboxRich(Xi)
                basicTrain(XXList[i], tb)
            else:
                tb = toolbox(Xi)
                basicTrain(XXList[i], tb)
            resSummarize.write()
            if config.rawResWrite:
                config.swResRaw.write('\n')
        if config.rawResWrite:
            config.swResRaw.write('\n')
示例#2
0
def train():
    print('\nreading training & test data...')
    config.swLog.write('\nreading training & test data...\n')
    if config.runMode.find('tune') >= 0:
        origX = dataSet(config.fFeatureTrain, config.fGoldTrain)
        X = dataSet()
        XX = dataSet()
        dataSplit(origX, config.tuneSplit, X, XX)
    else:
        X = dataSet(config.fFeatureTrain, config.fGoldTrain)
        XX = dataSet(config.fFeatureTest, config.fGoldTest)
        dataSizeScale(X)
    print('done! train/test data sizes: {}/{}'.format(len(X), len(XX)))
    config.swLog.write('done! train/test data sizes: {}/{}\n'.format(
        len(X), len(XX)))
    for r in config.regList:
        config.reg = r
        config.swLog.write('\nr: ' + str(r) + '\n')
        print('\nr: ' + str(r))
        if config.rawResWrite:
            config.swResRaw.write('\n%r: ' + str(r) + '\n')
        tb = toolbox(X, True)
        score = basicTrain(XX, tb)
        resSummarize.write()
        if config.save == 1:
            tb.Model.save(config.fModel)
        return score
示例#3
0
def test():
    config.swLog.write('reading test data...\n')
    XX = dataSet(config.fFeatureTest, config.fGoldTest)
    print('test data size: {}'.format(len(XX)))
    config.swLog.write('Done! test data size: {}'.format(len(XX)))
    tb = toolbox(XX, False)
    scorelist = tb.test(XX, 0)