Exemple #1
0
def test_random_walk():
    """Random input test for the Simple Random Walk kernel."""
    train, test = generate_dataset(n_graphs=100,
                                   r_vertices=(10, 20),
                                   r_connectivity=(0.4, 0.8),
                                   r_weight_edges=(0.01, 12.0),
                                   n_graphs_test=40,
                                   random_state=rs,
                                   features=None)

    rw_kernel = RandomWalk(verbose=verbose, normalize=normalize)
    try:
        rw_kernel.fit_transform(train)
        rw_kernel.transform(test)
        assert True
    except Exception as exception:
        assert False, exception
Exemple #2
0
y_pred = clf.predict(K_test)  # Predict

# Compute the classification accuracy
# hint: use the accuracy_score function of scikit-learn

##################
# your code here #
print(accuracy_score(y_test, y_pred))
##################

# Use the random walk kernel and the pyramid match graph kernel to perform classification

##################
# your code here #
gk1 = RandomWalk()
K_train1 = gk1.fit_transform(G_train)
K_test1 = gk1.transform(G_test)

clf1 = SVC(kernel='precomputed', C=1)  # Initialize SVM
clf1.fit(K_train, y_train)  # Train SVM
y_pred1 = clf1.predict(K_test)  # Predict

print(accuracy_score(y_test, y_pred1))
##################

############## Question 3
# Classify the graphs of a real-world dataset using graph kernels

# Load the MUTAG dataset
# hint: use the fetch_dataset function of GraKeL