RandomBaseline¶
-
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.
Note
Although the model still requires invoking the
fit()
method, no actual training will be carried out.Examples
>>> 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]
Methods
__init__
([seed])Initialize the model fit
(X)Train the random model predict
(X[, from_idx, get_ranks])Assign random scores to candidate triples and then ranks them -
__init__
(seed=0)¶ Initialize the model
Parameters: seed (int) – The seed used by the internal random numbers generator.
-
fit
(X)¶ Train the random model
Parameters: X (ndarray, shape [n, 3]) – The training triples
-
predict
(X, from_idx=False, get_ranks=False)¶ Assign random scores to candidate triples and then ranks them
Parameters: - X (ndarray, shape [n, 3]) – The triples to score.
- from_idx (bool) – If True, will skip conversion to internal IDs. (default: False).
- get_ranks (bool) – Flag to compute ranks by scoring against corruptions (default: False).
Returns: - scores (ndarray, shape [n]) – The predicted scores for input triples X.
- ranks (ndarray, shape [n]) – Rank of the triple
-