Пример #1
0
def main_with_validation(fileName, preproc=False, evalFunc = Util.brierScore):
    trainX, trainY, testX, testY = Util.readData(fileName, preproc)
        
    clf = GEVCanReg()
    regs = np.logspace(-3, 3, 7)
    xis = np.linspace(-1., 1.6, 14)
    bestScore, bestXi, bestReg = 1e10, None, None

    for xi in xis:
        clf.setXi(xi)
        print("Current xi = ", xi)
        score, reg = Util.crossValidate(clf, trainX, trainY, \
                                        evalFunc, 5, "Regular", regs)
        if score < bestScore:
            bestScore, bestXi, bestReg = score, xi, reg
    print("bestScore, bestXi, bestReg = ", bestScore, bestXi, bestReg)
    clf.setXi(bestXi)
    clf.setRegular(bestReg)
    clf.fit(trainX, trainY)
    testScore = evalFunc(clf.predict(testX), testY)
    with open("log/GEV_final_log.txt", 'a') as f:
        log = ','.join([dt.now().strftime("%Y/%m/%d %H:%M"), str(fileName), \
                        str(bestReg), str(bestXi), str(preproc), \
                        evalFunc.__name__, str(bestScore), str(testScore)])
        f.write(log + '\n')
Пример #2
0
def main_label(fileName, reg, xi, preproc=False, evalFunc = Util.f1):
    data = np.loadtxt(fname=fileName, delimiter=",")
    scoreList = []
    clf = GEVCanReg()
    clf.setRegular(reg)
    clf.setXi(xi)
    k = 10
    
    for _ in range(k):
        trainX, trainY, testX, testY = Util.readData(data, preproc)
        clf.fit(trainX, trainY)
        s = evalFunc(Util.probToLabel(clf.predict(testX)), testY)
        print("score = ", s)
        scoreList.append(s)
    print("mean score = ", sum(scoreList)/k)
Пример #3
0
def main_prob(fileName, reg, xi, preproc=False, evalFunc = Util.brierScore):
    data = np.loadtxt(fname=fileName, delimiter=",")
    scoreList = []
    clf = GEVCanReg()
    clf.setRegular(reg)
    clf.setXi(xi)
    k = 10
    
    for _ in range(k):
        trainX, trainY, testX, testY = Util.readData(data, preproc)
        clf.fit(trainX, trainY)
        s = evalFunc(clf.predict(testX), testY)
        print("score = ", s)
        scoreList.append(s)
    score = sum(scoreList)/k
    print("mean score = ", score)
    with open("log/GEV_test_log.txt", 'a') as f:
        log = ','.join([dt.now().strftime("%Y/%m/%d %H:%M"), str(fileName), \
                        str(preproc), evalFunc.__name__, str(score)])
        f.write(log + '\n')