Example #1
0
def test_graph_cross_validation():
    dataset = build_dataset_from_name('imdb-b')
    # first level, 10 folds
    utils.graph_cross_validation(dataset, 10)

    # set to fold id
    utils.set_fold(dataset, 1)

    # get train split
    train_dataset = utils.graph_get_split(dataset, "train", False)

    # further split train to train / val
    utils.graph_random_splits(train_dataset, 0.8, 0.2)
Example #2
0
import sys
sys.path.append('../')
from autogl.datasets import build_dataset_from_name, utils
from autogl.solver import AutoGraphClassifier
from autogl.module import Acc, BaseModel

dataset = build_dataset_from_name('mutag')
utils.graph_random_splits(dataset, train_ratio=0.4, val_ratio=0.4)

autoClassifier = AutoGraphClassifier.from_config(
    '../configs/graph_classification.yaml')

# train
autoClassifier.fit(
    dataset,
    time_limit=3600,
    train_split=0.8,
    val_split=0.1,
    cross_validation=True,
    cv_split=10,
)
autoClassifier.get_leaderboard().show()

print('best single model:\n',
      autoClassifier.get_leaderboard().get_best_model(0))

# test
predict_result = autoClassifier.predict_proba()
print(
    Acc.evaluate(predict_result,
                 dataset.data.y[dataset.test_index].cpu().detach().numpy()))
Example #3
0
                deg_max = int(
                    degree(data.edge_index[0], data.num_nodes).max().item())
                max_degree = max(max_degree, deg_max)
        else:
            max_degree = 0
            for data, _ in _converted_dataset:
                deg_max = data.in_degrees().max().item()
                max_degree = max(max_degree, deg_max)
        dataset = OneHotDegreeGenerator(max_degree).fit_transform(
            dataset, inplace=False)
    elif args.dataset == "collab":
        from autogl.module.feature._auto_feature import OnlyConstFeature

        dataset = OnlyConstFeature().fit_transform(dataset, inplace=False)
    utils.graph_random_splits(dataset,
                              train_ratio=0.8,
                              val_ratio=0.1,
                              seed=args.seed)

    autoClassifier = AutoGraphClassifier.from_config(args.configs)

    # train
    autoClassifier.fit(dataset, evaluation_method=[Acc], seed=args.seed)
    autoClassifier.get_leaderboard().show()

    print("best single model:\n",
          autoClassifier.get_leaderboard().get_best_model(0))

    # test
    acc = autoClassifier.evaluate(metric="acc")
    print("test acc {:.4f}".format(acc))
Example #4
0
from autogl.datasets import build_dataset_from_name
from autogl.solver import AutoGraphClassifier
from autogl.datasets import utils

mutag = build_dataset_from_name("mutag")
utils.graph_random_splits(mutag, 0.8, 0.1)

solver = AutoGraphClassifier(graph_models=("gin", ),
                             hpo_module=None,
                             device="auto")

solver.fit(mutag, evaluation_method=["acc"])
result = solver.predict(mutag)
print(
    "Acc:",
    sum([d.data["y"].item() == r
         for d, r in zip(mutag.test_split, result)]) / len(result))