class ampligraph.latent_features.RandomBaseline(seed=0)

Random baseline

A dummy model that assigns a pseudo-random score included between 0 and 1, drawn from a uniform distribution.

The model is useful whenever you need to compare the performance of another model on a custom knowledge graph, and no other baseline is available.


Although the model still requires invoking the fit() method, no actual training will be carried out.


>>> import numpy as np
>>> from ampligraph.latent_features import RandomBaseline
>>> model = RandomBaseline()
>>> X = np.array([['a', 'y', 'b'],
>>>               ['b', 'y', 'a'],
>>>               ['a', 'y', 'c'],
>>>               ['c', 'y', 'a'],
>>>               ['a', 'y', 'd'],
>>>               ['c', 'y', 'd'],
>>>               ['b', 'y', 'c'],
>>>               ['f', 'y', 'e']])
>>> model.fit(X)
>>> model.predict(np.array([['f', 'y', 'e'], ['b', 'y', 'd']]))
[0.5488135039273248, 0.7151893663724195]


__init__([seed]) Initialize the model
fit(X) Train the random model
predict(X[, from_idx]) Assign random scores to candidate triples and then ranks them

Initialize the model

Parameters:seed (int) – The seed used by the internal random numbers generator.

Train the random model

Parameters:X (ndarray, shape [n, 3]) – The training triples
predict(X, from_idx=False)

Assign random scores to candidate triples and then ranks them

  • X (ndarray, shape [n, 3]) – The triples to score.
  • from_idx (bool) – If True, will skip conversion to internal IDs. (default: False).

scores – The predicted scores for input triples X.

Return type:

ndarray, shape [n]