Esempio n. 1
0
def selectParamKNN(XTrain, yTrain, peopleTrain):
    KRange = np.arange(3, 11 + 1, 2)
    bestK = 0
    bestPerformance = 0
    for k in KRange:
        clf = KNeighborsClassifier(k)
        performance = util.cvPerformance(clf, XTrain, yTrain, peopleTrain)
        print "k = " + str(k) + ", accuracy = " + str(performance)
        if performance > bestPerformance:
            bestPerformance = performance
            bestK = k

    return bestK
Esempio n. 2
0
def selectParamLinear(XTrain, yTrain, peopleTrain):
    CRange = 10.0**np.arange(-4, 0)
    bestC = 0
    bestPerformance = 0
    for c in CRange:
        clf = SVC(kernel='linear', C=c)
        performance = util.cvPerformance(clf, XTrain, yTrain, peopleTrain)
        print "C = " + str(c) + ", accuracy = " + str(performance)
        if performance > bestPerformance:
            bestPerformance = performance
            bestC = c

    return bestC
Esempio n. 3
0
def selectParamLogReg(XTrain, yTrain, peopleTrain):
    CRange = 10.0**np.arange(-4, 1)
    bestC = 0
    bestPerformance = 0
    for c in CRange:
        clf = LogisticRegression(C=c,
                                 multi_class="multinomial",
                                 solver="sag",
                                 max_iter=1000)
        performance = util.cvPerformance(clf, XTrain, yTrain, peopleTrain)
        print "C = " + str(c) + ", accuracy = " + str(performance)
        if performance > bestPerformance:
            bestPerformance = performance
            bestC = c

    return bestC
Esempio n. 4
0
def selectParamRBF(XTrain, yTrain, peopleTrain):
    bestPerformance = 0
    bestTuple = (0, 0)
    gammaRange = 10.0**np.arange(-4, -1)
    CRange = 10.0**np.arange(0, 4)

    for gamma in gammaRange:
        for c in CRange:
            clf = SVC(kernel='rbf', C=c, gamma=gamma)
            score = util.cvPerformance(clf, XTrain, yTrain, peopleTrain)
            print "gamma = " + str(gamma) + ", C = " + str(
                c) + ", accuracy = " + str(score)
            if score > bestPerformance:
                bestPerformance = score
                bestTuple = (gamma, c)

    return bestTuple