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))
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))
f1_micro = f1_score(actuals, preds, average='micro') f1_macro = f1_score(actuals, preds, average='macro') print 'form: name,micro_f,macro_f,accuracy' print '###RESULTS###: %s,%s,%.6f,%.8f,%.8f,%.8f' % ( data_name, model_name, train_prop, f1_micro, f1_macro, accuracy) if __name__ == '__main__': np.random.seed() args = sys.argv[1:] name_to_data = { 'nci1': lambda: data.parse_nci(graph_name='nci1.graph'), 'nci109': lambda: data.parse_nci(graph_name='nci109.graph'), 'mutag': lambda: data.parse_nci(graph_name='mutag.graph'), 'ptc': lambda: data.parse_nci(graph_name='ptc.graph'), 'enzymes': lambda: data.parse_nci(graph_name='enzymes.graph'), 'nci1struct': lambda: data.parse_nci(graph_name='nci1.graph', with_structural_features=True), 'nci109struct': lambda: data.parse_nci(graph_name='nci109.graph', with_structural_features=True), }
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) if __name__ == '__main__': np.random.seed() args = sys.argv[1:] if len(args) == 0: graph_experiment(lambda: data.parse_nci('nci1.graph'), 'cora', 2) else: name_to_data = { 'nci1': lambda: data.parse_nci('nci1.graph'), #'nci1': lambda : data.parse_graph_data('nci1'), 'nci109': lambda: data.parse_nci('nci109.graph'), #'mutag': lambda : data.parse_graph_data('mutag'), 'mutag': lambda: data.parse_nci('mutag.graph'), 'enzymes': lambda: data.parse_nci('enzymes.graph'), 'ptc': lambda: data.parse_nci('ptc.graph'), 'nci1struct':
actuals = Y[test_indices, :] accuracy = accuracy_score(actuals, preds) f1_micro = f1_score(actuals, preds, average="micro") f1_macro = f1_score(actuals, preds, average="macro") print "form: name,micro_f,macro_f,accuracy" print "###RESULTS###: %s,%s,%.8f,%.8f,%.8f" % (data_name, model_name, f1_micro, f1_macro, accuracy) if __name__ == "__main__": np.random.seed() args = sys.argv[1:] name_to_data = { "nci1": lambda: data.parse_nci(graph_name="nci1.graph"), "nci109": lambda: data.parse_nci(graph_name="nci109.graph"), "nci1struct": lambda: data.parse_nci(graph_name="nci1.graph", with_structural_features=True), "nci109struct": lambda: data.parse_nci(graph_name="nci109.graph", with_structural_features=True), } name_to_parameters = { "nci1": { "num_dimensions": 2, "kernel_type": 1, "feature_type": 3, "ds_name": "nci1", "window_size": 2, "ngram_type": 0, "sampling_type": 1, "graphlet_size": 0,
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) if __name__ == '__main__': np.random.seed() args = sys.argv[1:] if len(args) == 0: graph_experiment(lambda : data.parse_nci('nci1.graph'), 'cora', 2) else: name_to_data = { 'nci1': lambda : data.parse_nci('nci1.graph'), 'nci109': lambda : data.parse_nci('nci109.graph'), 'nci1struct': lambda: data.parse_nci(graph_name='nci1.graph', with_structural_features=True), 'nci109struct': lambda: data.parse_nci(graph_name='nci109.graph', with_structural_features=True), } transform_lookup = { 'id': None, 'rwl': util.rw_laplacian, 'l': util.laplacian, } name = args[0]