Пример #1
0
def test_hmm():
    n_features = X.shape[1]

    clf = MultinomialHMM()
    clf.fit(X, y, lengths)
    assert_array_equal(clf.classes_, ["Adj", "DT", "IN", "N", "V"])
    assert_array_equal(clf.predict(X), y)

    clf.set_params(decode="bestfirst")
    assert_array_equal(clf.predict(X), y)

    n_classes = len(clf.classes_)
    assert_array_almost_equal(np.ones(n_features),
                              np.exp(clf.coef_).sum(axis=0))
    assert_array_almost_equal(np.ones(n_classes),
                              np.exp(clf.intercept_trans_).sum(axis=0))
    assert_array_almost_equal(1., np.exp(clf.intercept_final_).sum())
    assert_array_almost_equal(1., np.exp(clf.intercept_init_).sum())
def test_hmm():
    n_features = X.shape[1]

    clf = MultinomialHMM()
    clf.fit(X, y, lengths)
    assert_array_equal(clf.classes_, ["Adj", "DT", "IN", "N", "V"])
    assert_array_equal(clf.predict(X), y)

    clf.set_params(decode="bestfirst")
    assert_array_equal(clf.predict(X), y)

    n_classes = len(clf.classes_)
    assert_array_almost_equal(np.ones(n_features),
                              np.exp(clf.coef_).sum(axis=0))
    assert_array_almost_equal(np.ones(n_classes),
                              np.exp(clf.intercept_trans_).sum(axis=0))
    assert_array_almost_equal(1., np.exp(clf.intercept_final_).sum())
    assert_array_almost_equal(1., np.exp(clf.intercept_init_).sum())
Пример #3
0
X2 = mat1['X']
Y2 = mat1['Y']

mat_test = scipy.io.loadmat('test_subject1_psd04.mat')
test_X = mat_test['X']
true_label = np.loadtxt('test_subject1_true_label.csv', delimiter=",")

X = mat['X']
Y = mat['Y']

new_X = np.concatenate((X, X1, X2), axis=0)
new_Y = np.concatenate((Y, Y1, Y2), axis=0)

clf = MultinomialHMM()
clf.fit(new_X, new_Y, len(new_X))
clf.set_params(decode="bestfirst")
ans = clf.predict(test_X)

print 'sub-1, custom', accuracy_score(ans, true_label)
print confusion_matrix(true_label, ans)
#1440/3504: subject 1 accuracy
#start subject-2
sub2_1 = scipy.io.loadmat('train_subject2_psd01.mat')
sub2_X1 = sub2_1['X']
sub2_Y1 = sub2_1['Y']

sub2_2 = scipy.io.loadmat('train_subject2_psd02.mat')
sub2_X2 = sub2_2['X']
sub2_Y2 = sub2_2['Y']

sub2_3 = scipy.io.loadmat('train_subject2_psd03.mat')