예제 #1
0
def node_experiment(data_fn,
                    name,
                    n_hops,
                    transform_fn=util.rw_laplacian,
                    transform_name='rwl'):
    print 'Running node experiment (%s)...' % (name, )

    A, X, Y = data_fn()

    n_nodes = A.shape[0]

    indices = np.arange(n_nodes)
    np.random.shuffle(indices)

    train_indices = indices[:n_nodes // 3]
    valid_indices = indices[n_nodes // 3:(2 * n_nodes) // 3]
    test_indices = indices[(2 * n_nodes) // 3:]

    scnn = SCNN(n_hops=n_hops, transform_fn=transform_fn)
    scnn.fit(A, X, Y, train_indices=train_indices, valid_indices=valid_indices)

    probs = scnn.predict_proba(X, test_indices)
    print probs

    preds = scnn.predict(X, test_indices)
    actuals = np.argmax(Y[test_indices, :], axis=1)

    f1_micro = f1_score(actuals, preds, average='micro')
    f1_macro = f1_score(actuals, preds, average='macro')
    accuracy = accuracy_score(actuals, preds)

    print 'form: name,n_hops,transform_name,micro_f,macro_f,accuracy'
    print '###RESULTS###: %s,%d,%s,%.8f,%.8f,%.8f' % (
        name, n_hops, transform_name, f1_micro, f1_macro, accuracy)
예제 #2
0
def scnn_proportion_experiment(data_fn, name, n_hops, prop_valid, prop_test, transform_fn=util.rw_laplacian, transform_name='rwl'):
    print 'Running node experiment (%s)...' % (name,)

    A, X, Y = data_fn()

    n_nodes = A.shape[0]

    indices = np.arange(n_nodes)

    valid_start = int(n_nodes * (1 - (prop_valid + prop_test)))
    test_start = int(n_nodes * (1 - prop_test))

    valid_indices = indices[valid_start:test_start]
    test_indices  = indices[test_start:]

    for train_prop in [x / 10.0 for x in range(1, 11)]:
        train_end = int(valid_start * train_prop)
        train_indices = indices[:train_end]

        scnn = SCNN(n_hops=n_hops, transform_fn=transform_fn)
        scnn.fit(A, X, Y, train_indices=train_indices, valid_indices=valid_indices)

        probs = scnn.predict_proba(X, test_indices)
        print probs

        preds = scnn.predict(X, test_indices)
        actuals = np.argmax(Y[test_indices,:], axis=1)

        f1_micro = f1_score(actuals, preds, average='micro')
        f1_macro = f1_score(actuals, preds, average='macro')
        accuracy = accuracy_score(actuals, preds)

        print 'form: name,n_hops,transform_name,micro_f,macro_f,accuracy'
        print '###RESULTS###: %s,%d,%.2f,%s,%.8f,%.8f,%.8f' % (name, n_hops, train_prop, transform_name, f1_micro, f1_macro, accuracy)
예제 #3
0
def node_experiment(data_fn, name, n_hops, transform_fn=util.rw_laplacian, transform_name='rwl'):
    print 'Running node experiment (%s)...' % (name,)

    A, X, Y = data_fn()

    n_nodes = A.shape[0]

    indices = np.arange(n_nodes)
    np.random.shuffle(indices)

    train_indices = indices[:n_nodes // 3]
    valid_indices = indices[n_nodes // 3:(2* n_nodes) // 3]
    test_indices  = indices[(2* n_nodes) // 3:]

    scnn = SCNN(n_hops=n_hops, transform_fn=transform_fn)
    scnn.fit(A, X, Y, train_indices=train_indices, valid_indices=valid_indices)

    probs = scnn.predict_proba(X, test_indices)
    print probs

    preds = scnn.predict(X, test_indices)
    actuals = np.argmax(Y[test_indices,:], axis=1)

    f1_micro = f1_score(actuals, preds, average='micro')
    f1_macro = f1_score(actuals, preds, average='macro')
    accuracy = accuracy_score(actuals, preds)

    print 'form: name,n_hops,transform_name,micro_f,macro_f,accuracy'
    print '###RESULTS###: %s,%d,%s,%.8f,%.8f,%.8f' % (name, n_hops, transform_name, f1_micro, f1_macro, accuracy)
예제 #4
0
def scnn_proportion_experiment(data_fn,
                               name,
                               n_hops,
                               prop_valid,
                               prop_test,
                               transform_fn=util.rw_laplacian,
                               transform_name='rwl'):
    print 'Running node experiment (%s)...' % (name, )

    A, X, Y = data_fn()

    n_nodes = A.shape[0]

    indices = np.arange(n_nodes)

    valid_start = int(n_nodes * (1 - (prop_valid + prop_test)))
    test_start = int(n_nodes * (1 - prop_test))

    valid_indices = indices[valid_start:test_start]
    test_indices = indices[test_start:]

    for train_prop in [x / 10.0 for x in range(1, 11)]:
        train_end = int(valid_start * train_prop)
        train_indices = indices[:train_end]

        scnn = SCNN(n_hops=n_hops, transform_fn=transform_fn)
        scnn.fit(A,
                 X,
                 Y,
                 train_indices=train_indices,
                 valid_indices=valid_indices)

        probs = scnn.predict_proba(X, test_indices)
        print probs

        preds = scnn.predict(X, test_indices)
        actuals = np.argmax(Y[test_indices, :], axis=1)

        f1_micro = f1_score(actuals, preds, average='micro')
        f1_macro = f1_score(actuals, preds, average='macro')
        accuracy = accuracy_score(actuals, preds)

        print 'form: name,n_hops,transform_name,micro_f,macro_f,accuracy'
        print '###RESULTS###: %s,scnn%d%s,%.6f,%.8f,%.8f,%.8f' % (
            name, n_hops, transform_name, train_prop, f1_micro, f1_macro,
            accuracy)