You are reading Quantum Evolution Kernel v0.2.9, an older version of this documentation. Go to the latest version (v0.3.4)
Usage
# Load a datasetimport torch_geometric.datasets as pyg_datasetog_ptcfm = pyg_dataset.TUDataset(root="dataset", name="PTC_FM")
# Setup a quantum feature extractor for this dataset.# In this example, we'll use QutipExtractor, to emulate a Quantum Device on our machine.import qek.data.graphs as qek_graphsimport qek.data.extractors as qek_extractorsextractor = qek_extractors.QutipExtractor(compiler=qek_graphs.PTCFMCompiler())
# Add the graphs, compile them and look at the results.extractor.add_graphs(graphs=og_ptcfm)extractor.compile()processed_dataset = extractor.run().processed_data
# Prepare a machine learning pipeline with Scikit Learn.from sklearn.model_selection import train_test_splitfrom sklearn.svm import SVC
X = [data for data in processed_dataset] # Featuresy = [data.target for data in processed_dataset] # TargetsX_train, X_test, y_train, y_test = train_test_split(X, y, stratify = y, test_size=0.2, random_state=42)
# Train a kernelfrom qek.kernel import QuantumEvolutionKernel as QEKkernel = QEK(mu=0.5)model = SVC(kernel=kernel, random_state=42)model.fit(X_train, y_train)