Skip to main content

Graph Embedding Models

Project description

Graph Embedding

Introduction

This module provides the services and implementation for various graph embedding models.

Getting Started

Installation

You can install the DGLL Graph Embedding version 1.0.3 from PyPI as:

pip install dgllge

Usage and Tutorial

input graph

# import module
import ge


# Set Path to Data
data_dir = "Your Path to Data"
dataset = "File/Dataset Name"


# Load a Graph
inputGraph = ge.loadGraph(data_dir, dataset)

Configurable Parameter for Graph Embedding

embedDim = 2 # embedding size
numbOfWalksPerVertex = 2 # walks per vertex
walkLength = 4 # walk lenght
lr =0.025 # learning rate
windowSize = 3 # window size

Choose One of the Following Graph Embedding Models

# DeepWalk
rw = ge.DeepWalk(inputGraph, walkLength=walkLength, embedDim=embedDim, numbOfWalksPerVertex=numbOfWalksPerVertex, \
              windowSize=windowSize, lr = lr)
              
# Node2Vec
rw = ge.Node2vec(inputGraph, walkLength=walkLength, embedDim=embedDim, numbOfWalksPerVertex=numbOfWalksPerVertex, \
               windowSize=windowSize, lr=lr, p = 0.5, q = 0.8)
# Struc2Vec
rw = ge.Struc2Vec(inputGraph, walkLength=walkLength, embedDim=embedDim, numbOfWalksPerVertex=numbOfWalksPerVertex, \
              windowSize=windowSize, lr = lr)

Skip Gram model

modelSkipGram = ge.SkipGramModel(rw.totalNodes, rw.embedDim)

Want Node Embedding or Edge Embedding

# Learning Node Embedding
model = rw.learnNodeEmbedding(modelSkipGram)
# Learning Edge Embedding
model = rw.learnEdgeEmbedding(modelSkipGram)

Plot Embedding

ge.plot_2DEmbedding(rw)

Save Embedding to Disk

ge.saveEmbedding(data_dir, dataset, rw)

Generate Embedding for a Specific Node or Edge

node1 = 35
node2 = 40

# Get Embedding for a node
emb = rw.getNodeEmbedding(node1)
print("Node Embedding", emb)

# Get Embedding for an edge
emb = rw.getEdgeEmbedding(node1, node2)
print("Edge Embedding", emb)

Utilize embedding for training classification models/classifiers

# import modules
import ge
import numpy as np
import scipy.sparse as sp

Load Embedding

idsEmbeddingClsLabels = np.genfromtxt("cora.embedding", dtype=np.dtype(str))

Prepare data for training

labels = idsEmbeddingClsLabels[:, -1]
embedding = sp.csr_matrix(idsEmbeddingClsLabels[:, 1:-1], dtype=np.float32)
tr = ge.TrainingClassifiers()
y = tr.labelEnocder(labels)

Prepare Train test data

X_train, X_test, y_train, y_test = tr.prepareTrainTestData(embedding, labels, 0.33)

Choose one of the following classifier for training a classifier

y_pred = tr.applyDecisionTree(X_train.toarray(), y_train, X_test.toarray())
y_pred = tr.applyLogistic(X_train.toarray(), y_train, X_test.toarray())
y_pred = tr.applyRandomForest(X_train.toarray(), y_train, X_test.toarray())
y_pred = tr.apply_GradientBoosting(X_train.toarray(), y_train, X_test.toarray())
y_pred = tr.applyMLP(X_train.toarray(), y_train, X_test.toarray())

Get Accuracy

print("Accuracy:", tr.accuracy(y_test, y_pred))

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Acknowledgments

(back to top)

Links

Project's GitHub Link: @Graph-Embedding

Project's PyPI Link: @dgllge

(back to top)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dgllge-1.0.3.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dgllge-1.0.3-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file dgllge-1.0.3.tar.gz.

File metadata

  • Download URL: dgllge-1.0.3.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.5

File hashes

Hashes for dgllge-1.0.3.tar.gz
Algorithm Hash digest
SHA256 0a7102387c03fb2fad1977fd729d150785fb5003b1b7e5a13619b44236c79697
MD5 959e63c85d3a353098475bdccfe814ab
BLAKE2b-256 4e5a2e8ba4d34121f6f0ef9e915489bb4eb7e955895c76ec6a6493f30476d499

See more details on using hashes here.

File details

Details for the file dgllge-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: dgllge-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.5

File hashes

Hashes for dgllge-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 013c20c3f41e68ed861ddbbdae6de199ff0e09e4a96734efc1d2698b2d4c5e7b
MD5 629debb89de5d19419aa1df7bab6bf3a
BLAKE2b-256 023285d2cdf59f10897d84a28dab9e2975a68c337e85961605ee5299e14889f1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page