Logo
master

Getting started

  • Overview
  • Installation
  • Import
  • Usage

User manual

  • Data
  • Topology
  • Path
  • Clustering
  • Classification
  • GNN
  • Regression
  • Hierarchy
  • Embedding
  • Ranking
  • Link prediction
    • Nearest neighbors
  • Linear algebra
  • Utils
  • Visualization

Tutorials

  • Overview
  • Data
  • Topology
  • Path
  • Clustering
  • Classification
  • GNN
  • Regression
  • Hierarchy
  • Embedding
  • Ranking
  • Link prediction
  • Visualization

Examples

  • Text mining
  • Wikipedia
  • Recommendation
  • Politics
  • Sport

About

  • Credits
  • History
  • Contributing
  • Index
  • Glossary
scikit-network
  • »
  • Link prediction
  • Edit on GitHub

Link prediction

Link prediction algorithms.

The attribute links_ gives the predicted links of each node as a sparse matrix.

Nearest neighbors

class sknetwork.linkpred.NNLinker(n_neighbors: Optional[int] = 10, threshold: float = 0, embedding_method: Optional[sknetwork.embedding.base.BaseEmbedding] = None)[source]

Link prediction by nearest neighbors in the embedding space, using cosine similarity.

For bipartite graphs, predict links between rows and columns only.

Parameters
  • n_neighbors – Number of nearest neighbors. If None, all nodes are considered.

  • threshold – Threshold on cosine similarity. Only links above this threshold are kept.

  • embedding_method – Embedding method used to represent nodes in vector space. If None (default), use identity.

Variables

links_ (sparse.csr_matrix) – Link matrix.

Example

>>> from sknetwork.linkpred import NNLinker
>>> from sknetwork.data import karate_club
>>> linker = NNLinker(n_neighbors=5, threshold=0.5)
>>> graph = karate_club(metadata=True)
>>> adjacency = graph.adjacency
>>> links = linker.fit_predict(adjacency)
>>> links.shape
(34, 34)
fit(input_matrix: Union[scipy.sparse._csr.csr_matrix, numpy.ndarray], index: Optional[numpy.ndarray] = None) → sknetwork.linkpred.nn.NNLinker[source]

Link prediction by nearest neighbors in the embedding space, using cosine similarity

Parameters
  • input_matrix – Adjacency matrix or biadjacency matrix of the graph.

  • index – Index of source nodes to consider. If None, the links are predicted for all nodes.

Returns

self

Return type

NN

fit_predict(*args, **kwargs) → numpy.ndarray

Fit algorithm to data and return the links. Same parameters as the fit method.

Returns

links_ – Link matrix.

Return type

sparse.csr_matrix

get_params()

Get parameters as dictionary.

Returns

params – Parameters of the algorithm.

Return type

dict

set_params(params: dict) → sknetwork.base.Algorithm

Set parameters of the algorithm.

Parameters

params (dict) – Parameters of the algorithm.

Returns

self

Return type

Algorithm

Previous Next

© Copyright 2020, scikit-network. Revision 95cec38d.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: master
Versions
master
latest
stable
v0.26.0
Downloads
On Read the Docs
Project Home
Builds