def get_the_iter_accucy(max_true_vale=70, model="model/GNB.model", iter_times=3):
    try:
        if iter_times > 0:
            print "left " + str(iter_times) + " iteration"
            a, b = load_data_X_Y('train')
            X, y = shuffle_two_list_X_Y(a, b)
            gnb = GaussianNB()
            gnb.fit(X, y)

            testX, testY = load_data_X_Y('test')
            true_ans = 0

            for itemX in range(len(testX)):
                predict_result = gnb.predict(testX[itemX])
                vote_vale = vote_the_max_times(predict_result)
                if vote_vale == testY[itemX]:
                    true_ans += 1
            true_ans_percent = true_ans * 100 / len(testX)
            print true_ans_percent
            if true_ans_percent > max_true_vale:
                print "good job, the new record:"

                joblib.dump(gnb, model)
                print "update the model"
            else:
                true_ans_percent = max_true_vale
            get_the_iter_accucy(true_ans_percent, model, iter_times - 1)
    except ValueError:
        pass
    return 0
Example #2
0
def get_accucy(model="model/GB/GB.model"):
    try:
        clf = joblib.load(model)
        print 'load GB model successfully'
    except IOError:

        print 'GB model file doesnt exist, Train first'
        a, b = load_data_X_Y('train')
        # X, y = shuffle_two_list_X_Y(a, b)
        X, y = a, b
        #clf = gaussian_process.GaussianProcess(theta0=1e-2, thetaL=1e-4, thetaU=1e-1)
        clf = GradientBoostingClassifier(n_estimators=100,
                                         learning_rate=1.0,
                                         max_depth=1,
                                         random_state=0)
        clf.fit(X, y)
        joblib.dump(clf, "model/GB/GB.model")
        print "update the model"
    testX, testY = load_data_X_Y('test')
    true_ans = 0

    for itemX in range(len(testX)):
        predict_result = clf.predict(testX[itemX])
        vote_vale = vote_the_max_times(predict_result)
        if vote_vale == testY[itemX]:
            true_ans += 1
    true_ans_percent = true_ans * 100 / len(testX)

    return true_ans_percent


# get_the_iter_accucy()
# print get_accucy()
def get_accucy(model="model/GNB.model"):
    try:
        gnb = joblib.load(model)
        print 'load GNBClassifier successfully'
    except IOError, ValueError:

        print 'GNB classifer file doesnt exist, Train first'
        a, b = load_data_X_Y('train')
        X, y = shuffle_two_list_X_Y(a, b)
        gnb = GaussianNB()
        gnb.fit(X, y)
Example #4
0
def get_accucy(model="model/DT.model"):
    try:
        dt = joblib.load(model)
        print 'load DTClassifier successfully'
    except IOError, ValueError:

        print 'DT classifer file doesnt exist, Train first'
        a, b = load_data_X_Y('train')
        X, y = shuffle_two_list_X_Y(a, b)
        dt = DecisionTreeClassifier()
        dt.fit(X, y)
def get_accucy(model="model/SGD.model"):
    try:
        sgd = joblib.load(model)
        print 'load SGDClassifier successfully'
    except IOError:

        print 'SGD classifer file doesnt exist, Train first'
        a, b = load_data_X_Y('train')
        X, y = shuffle_two_list_X_Y(a, b)
        sgd = SGDClassifier(loss="hinge", penalty="l2", n_iter=10000)
        sgd.fit(X, y)
    testX, testY = load_data_X_Y('test')
    true_ans = 0

    for itemX in range(len(testX)):
        predict_result = sgd.predict(testX[itemX])
        vote_vale = vote_the_max_times(predict_result)
        if vote_vale == testY[itemX]:
            true_ans += 1
    true_ans_percent = true_ans * 100 / len(testX)

    return true_ans_percent
Example #6
0
def get_the_iter_accucy(max_true_vale=76,
                        model="model/GB/GB.model",
                        iter_times=1):
    try:
        if iter_times > 0:
            print "left " + str(iter_times) + " iteration"
            a, b = load_data_X_Y('train')
            # X, y = shuffle_two_list_X_Y(a, b)
            X, y = a, b
            #clf = gaussian_process.GaussianProcess(theta0=1e-2, thetaL=1e-4, thetaU=1e-1)
            clf = GradientBoostingClassifier(n_estimators=100,
                                             learning_rate=1.0,
                                             max_depth=1,
                                             random_state=0)
            clf.fit(X, y)
            joblib.dump(clf, "model/GB/GB.model")
            print "update the model"

            testX, testY = load_data_X_Y('test')
            true_ans = 0

            for itemX in range(len(testX)):
                predict_result = clf.predict(testX[itemX])
                vote_vale = vote_the_max_times(predict_result)
                if vote_vale == testY[itemX]:
                    true_ans += 1
            true_ans_percent = true_ans * 100 / len(testX)
            print true_ans_percent
            if true_ans_percent > max_true_vale:
                print "good job, the new record:"

                joblib.dump(clf, model)
                print "update the model"
            else:
                true_ans_percent = max_true_vale
            get_the_iter_accucy(true_ans_percent, model, iter_times - 1)
    except ValueError:
        pass
    return 0
def start_calssification_SGD(wav):
    try:
        sgd = joblib.load('model/SGD.model')
        print 'load SGDClassifier successfully'
    except IOError:

        print 'SGD classifer file doesnt exist, Train first'
        a, b = load_data_X_Y('train')
        X, y = shuffle_two_list_X_Y(a, b)
        sgd = SGDClassifier(loss="hinge", penalty="l2", n_iter=10000)
        sgd.fit(X, y)

    predict_result = sgd.predict(load_data_user_chose(wav))
    vote_vale = vote_the_max_times(predict_result)
    speaker_name = get_speaker_name(vote_vale)
    return speaker_name
def start_calssification_GNB(wav):
    try:
        gnb = joblib.load('model/GNB.model')
        print 'load GNBClassifier successfully'
    except IOError:

        print 'GNB classifer file doesnt exist, Train first'
        a, b = load_data_X_Y('train')
        X, y = shuffle_two_list_X_Y(a, b)
        gnb = GaussianNB()
        gnb.fit(X, y)
        joblib.dump(gnb, 'model/GNB.model')
        print "update the model"

    predict_result = gnb.predict(load_data_user_chose(wav))
    vote_vale = vote_the_max_times(predict_result)
    speaker_name = get_speaker_name(vote_vale)
    return speaker_name
Example #9
0
def start_calssification_DT(wav):
    try:
        dt = joblib.load('model/DT.model')
        print 'load DTClassifier successfully'
    except IOError:

        print 'DT classifer file doesnt exist, Train first'
        a, b = load_data_X_Y('train')
        X, y = shuffle_two_list_X_Y(a, b)
        dt = DecisionTreeClassifier()
        dt.fit(X, y)
        joblib.dump(dt, 'model/DT.model')
        print "update the model"

    predict_result = dt.predict(load_data_user_chose(wav))
    vote_vale = vote_the_max_times(predict_result)
    speaker_name = get_speaker_name(vote_vale)
    return speaker_name
Example #10
0
def start_GradientBoostingClassifier(wav):
    try:
        clf = joblib.load('model/GB/GB.model')
        print 'load GB model successfully'
    except IOError:

        print 'GB model file doesnt exist, Train first'
        a, b = load_data_X_Y('train')
        # X, y = shuffle_two_list_X_Y(a, b)
        X, y = a, b
        #clf = gaussian_process.GaussianProcess(theta0=1e-2, thetaL=1e-4, thetaU=1e-1)
        clf = GradientBoostingClassifier(n_estimators=100,
                                         learning_rate=1.0,
                                         max_depth=1,
                                         random_state=0)
        clf.fit(X, y)
        joblib.dump(clf, "model/GB/GB.model")
        print "update the model"

    predict_result = clf.predict(load_data_user_chose(wav))
    vote_vale = vote_the_max_times(predict_result)
    speaker_name = get_speaker_name(vote_vale)
    return speaker_name
        pass
    return 0


def get_accucy(model="model/GNB.model"):
    try:
        gnb = joblib.load(model)
        print 'load GNBClassifier successfully'
    except IOError, ValueError:

        print 'GNB classifer file doesnt exist, Train first'
        a, b = load_data_X_Y('train')
        X, y = shuffle_two_list_X_Y(a, b)
        gnb = GaussianNB()
        gnb.fit(X, y)
    testX, testY = load_data_X_Y('test')
    true_ans = 0

    for itemX in range(len(testX)):
        predict_result = gnb.predict(testX[itemX])
        vote_vale = vote_the_max_times(predict_result)
        if vote_vale == testY[itemX]:
            true_ans += 1
    true_ans_percent = true_ans * 100 / len(testX)

    return true_ans_percent


# get_the_iter_accucy()
# print get_accucy()
Example #12
0
        #clf = gaussian_process.GaussianProcess(theta0=1e-2, thetaL=1e-4, thetaU=1e-1)
        clf = GradientBoostingClassifier(n_estimators=100,
                                         learning_rate=1.0,
                                         max_depth=1,
                                         random_state=0)
        clf.fit(X, y)
        joblib.dump(clf, "model/GB/GB.model")
        print "update the model"

    predict_result = clf.predict(load_data_user_chose(wav))
    vote_vale = vote_the_max_times(predict_result)
    speaker_name = get_speaker_name(vote_vale)
    return speaker_name


test1, test2 = load_data_X_Y('train')


# print start_calssification_SGD()
def get_the_iter_accucy(max_true_vale=76,
                        model="model/GB/GB.model",
                        iter_times=1):
    try:
        if iter_times > 0:
            print "left " + str(iter_times) + " iteration"
            a, b = load_data_X_Y('train')
            # X, y = shuffle_two_list_X_Y(a, b)
            X, y = a, b
            #clf = gaussian_process.GaussianProcess(theta0=1e-2, thetaL=1e-4, thetaU=1e-1)
            clf = GradientBoostingClassifier(n_estimators=100,
                                             learning_rate=1.0,