Пример #1
0
def test_graph_scnn():
    from sklearn.metrics import accuracy_score
    A, X, Y = data.parse_nci()

    n_graphs = len(A)

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

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

    scnn = GraphSCNN(n_hops=5)
    scnn.fit(A,
             X,
             Y,
             train_indices=train_indices,
             valid_indices=valid_indices,
             learning_rate=0.05,
             batch_size=100,
             n_epochs=500)

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

    print 'Accuracy: %.4f' % (accuracy_score(actuals, preds))
Пример #2
0
def graph_experiment(data_fn, name, n_hops, transform_fn=util.rw_laplacian, transform_name='rwl'):
    A, X, Y = data_fn()

    n_graphs = len(A)

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

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

    scnn = GraphSCNN(n_hops=n_hops, transform_fn=transform_fn)
    scnn.fit(A, X, Y, train_indices=train_indices, valid_indices=valid_indices,
             learning_rate=0.05, batch_size=100, n_epochs=500)

    preds = scnn.predict(A, 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)
Пример #3
0
def scnn_graph_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_graphs = len(A)

    indices = np.arange(n_graphs)
    np.random.seed(4)
    np.random.shuffle(indices)
    print indices

    valid_start = int(n_graphs * (1 - (prop_valid + prop_test)))
    test_start = int(n_graphs * (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 = GraphSCNN(n_hops=n_hops, transform_fn=transform_fn)
        scnn.fit(A,
                 X,
                 Y,
                 train_indices=train_indices,
                 valid_indices=valid_indices)

        preds = scnn.predict(A, 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)
Пример #4
0
def test_graph_scnn():
    from sklearn.metrics import accuracy_score
    A, X, Y = data.parse_nci()

    n_graphs = len(A)

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

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

    scnn = GraphSCNN(n_hops=5)
    scnn.fit(A, X, Y, train_indices=train_indices, valid_indices=valid_indices,
             learning_rate=0.05, batch_size=100, n_epochs=500)


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

    print 'Accuracy: %.4f' % (accuracy_score(actuals, preds))
Пример #5
0
def graph_experiment(data_fn,
                     name,
                     n_hops,
                     transform_fn=util.rw_laplacian,
                     transform_name='rwl'):
    A, X, Y = data_fn()

    n_graphs = len(A)

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

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

    scnn = GraphSCNN(n_hops=n_hops, transform_fn=transform_fn)
    scnn.fit(A,
             X,
             Y,
             train_indices=train_indices,
             valid_indices=valid_indices,
             learning_rate=0.05,
             batch_size=len(train_indices) // 10,
             n_epochs=500)

    preds = scnn.predict(A, 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)