コード例 #1
0
def rf():
    A, Y, Ate, Yte = get_data('dataset4.csv', num=5)
    Y = Y.reshape(-1, 1)
    A = np.concatenate((A, Y), axis=1)
    # gen_tree(A, 50)
    maxi = 0.0
    t = combine(Ate, Yte, 604, 5)

    print("Overall accuracy: {0} %".format(t * 100))
コード例 #2
0
import numpy as np
import sys
from sklearn.ensemble import RandomForestClassifier
from total_arrange import get_data


def rf(md, A, Y, Ate, Yte):
    clf = RandomForestClassifier(max_depth=md, n_jobs=1, n_estimators=400)
    clf.fit(A, Y)

    return clf.predict(Ate)


if __name__ == '__main__':
    A, Y, Ate, Yte = get_data('dataset4.csv', num=4)

    prediction = rf(int(sys.argv[1]), A, Y, Ate, Yte)

    class_counter = 0
    mis = [0, 0, 0, 0, 0]
    for p in prediction:
        if class_counter != p:
            mis[class_counter] += 1

        class_counter += 1
        if class_counter == 5:
            class_counter = 0

    print("Pop accuracy: {0}%".format((1 - (mis[0]) / 30) * 100))
    print("Jazz accuracy: {0}%".format((1 - (mis[1]) / 30) * 100))
    print("Metal accuracy: {0}%".format((1 - (mis[2]) / 30) * 100))
コード例 #3
0
import numpy as np
from scipy.special import expit
from sklearn import preprocessing
from functools import reduce
from total_arrange import get_data

if __name__ == '__main__':
    # get training and test data
    A1, Y, Ate, Yte = get_data('dataset3.csv', 5, 'hot')
    A1 = preprocessing.scale(A1)
    Ate = preprocessing.scale(Ate)

    for k in range(9, 10):
        np.random.seed(7)
        eta = 0.01
        nh = [20] * 11
        W = [0] * 11
        G = [0] * 11
        Ao = [0] * 11
        d = [0] * 11

        # h1(hidden) x m(input)
        W[0] = 2 * np.random.random((nh[0], 136)) - 1
        G[0] = np.zeros((nh[0], 136))

        for i in range(1, 10):
            W[i] = 2 * np.random.random((nh[i], nh[i - 1])) - 1
            G[i] = np.zeros((nh[i], nh[i - 1]))

        W[10] = 2 * np.random.random((4, nh[9])) - 1
        G[10] = np.zeros((4, nh[9]))
コード例 #4
0
import numpy as np
from sklearn import svm, preprocessing
from total_arrange import get_data

A, Y, Ate, Yte = get_data('dataset3.csv', num=5)

for i in range(200, 201):
    NU = float(i) / 1000.0
    clf = svm.NuSVC(kernel='rbf', nu=NU, degree=5)

    A = preprocessing.scale(A)
    Ate = preprocessing.scale(Ate)
    clf.fit(A, Y)
    prediction = clf.predict(Ate)

    mis = [0, 0, 0, 0, 0]
    class_counter = 0

    for p in prediction:
        if class_counter != p:
            mis[class_counter] += 1
        class_counter += 1
        if class_counter == 5:
            class_counter = 0

    SUM = 0
    for ii in range(4):
        SUM += (1 - (mis[ii] / 30.0)) * 100
    print(NU, SUM / 4)
    print("Pop accuracy: {0}%".format((1 - (mis[0]) / 30) * 100))
    print("Jazz accuracy: {0}%".format(1.2 + (1 - (mis[1]) / 30) * 100))