Пример #1
0
def main_ordinal(fileName, clf, k=3, preproc=False, evalFunc = Util.brierScore):
    data = np.loadtxt(fname=fileName, delimiter=",")
    hda = HighDimAlg(clf, "ordinal", kTimes=k)
    scoreList = []
    nRunning = 10
    for _ in range(nRunning):
        trainX, trainY, testX, testY = Util.readData(data, False, preproc)
        hda.fit(trainX, trainY)
        s = evalFunc(hda.predict(testX), testY)
        print("score = ", s)
        scoreList.append(s)
    score = sum(scoreList)/nRunning
    print("mean score = ", score)
    with open("log/HDA_test_log_ordinal.txt", 'a') as f:
        log = ','.join([dt.now().strftime("%Y/%m/%d %H:%M"), str(fileName), \
                        "GLS", str(k), \
                        str(preproc), evalFunc.__name__, str(score)])
        f.write(log + '\n')
Пример #2
0
def worker(chosenNum):
    print("Current chosen number: ", chosenNum)
#    global validateX, validateY, trainX, trainY, regs, xis, lock, clfs
    clf = GLS()
    hda = HighDimAlg(clf, "convolve")       
    hda.setWidth(28)
    hda.setKernels([(2,2), (4,4), (7,7)])
    
    target = validateY.copy()
    target[target == chosenNum] = 999
    target[target != 999] = 0
    target[target == 999] = 1
    
    bestScore, bestXi, bestReg = 1e10, None, None 
    
    for xi in xis:
        hda.setXi(xi)
        score, reg = Util.crossValidate(hda, validateX, target, \
                                        Util.brierScore, 2, "Regular", regs)
        if score < bestScore:
            bestScore, bestXi, bestReg = score, xi, reg
    print("bestScore, bestXi, bestReg = ", bestScore, bestXi, bestReg)
    hda.setXi(bestXi)
    hda.setRegular(bestReg)
    
    target = trainY.copy()
    target[target == chosenNum] = 999
    target[target != 999] = 0
    target[target == 999] = 1
    hda.fit(trainX, target)
    
    res = {}
    res['num'] = chosenNum
    res['clf'] = hda
    res['validateScore'] = bestScore
    lock.acquire()
    try:
        clfs.append(res)
    finally:
        lock.release()