NETWORK.SIMILARITY OpenBI
Finds the nodes that are alike because they have the same neighbours, such as beers bought by the same customers.
Group: Networks. OpenBI’s own: DAX has no function of this name.
Syntax
NETWORK.SIMILARITY ( <links>, <from>, <to> [, <method>] [, <top>] [, <threshold>] )
| Parameter | Type | Description |
|---|---|---|
links | Table | The rows that make the network, one link a row: a table of the model or a table expression, as the filters leave it. |
from | Expression evaluated for each row | One end of each row's link, such as a payer, a customer or a place. |
to | Expression evaluated for each row | The other end of each row's link. |
method | Text optional | "jaccard" (when left out), "dice", "cosine" or "adamic-adar". |
top | Whole number optional | How many of each node's most similar nodes are kept: 10 when left out, 0 for every pair. |
threshold | Number optional | Keep only pairs at least this similar, such as 0.5 for half their neighbours shared (Jaccard). Left out, every pair the top keeps. |
Returns
Table. A row a pair, with the columns Node, Other, Shared (the neighbours they have in common) and Similarity.
Remarks
- Two nodes are alike when they have the same neighbours, whether or not they are linked themselves: two products bought by the same customers, two customers who buy the same products.
- Jaccard is shared / (all the neighbours of either); Dice is 2 × shared / (the sum of their neighbours); cosine is shared / √(the product of their numbers of neighbours); Adamic-Adar adds 1 / ln(neighbours) for each shared neighbour, so one shared with few others counts more.
- Only pairs with at least one neighbour in common appear. Each pair appears twice, once from each side; each node's most similar come first.
- The links are taken both ways, and no weight is used.
- In a network of two kinds of node, such as customers and products, the result holds pairs of both kinds: filter it to the kind you want.
Compared with DAX
An OpenBI function: DAX has none like it, so a measure or query that uses it works in OpenBI only, not in Power BI or Analysis Services.
Examples
Beers bought by the same customers
Pils and IPA share two of their three customers, and so do Stout and Cider.
EVALUATE
VAR Baskets =
DATATABLE (
"Customer", STRING, "Product", STRING,
{
{ "Ola", "Pils" }, { "Ola", "IPA" }, { "Kari", "Pils" }, { "Kari", "IPA" }, { "Kari", "Stout" },
{ "Per", "Stout" }, { "Per", "Cider" }, { "Liv", "Cider" }, { "Liv", "Stout" }, { "Nils", "Pils" }
}
)
RETURN
FILTER (
NETWORK.SIMILARITY ( Baskets, [Customer], [Product] ),
[Node] IN { "Pils", "IPA", "Stout", "Cider" }
)
ORDER BY [Node], [Similarity] DESC, [Other]
| Node | Other | Shared | Similarity |
|---|---|---|---|
| Cider | Stout | 2 | 0.666666666666667 |
| IPA | Pils | 2 | 0.666666666666667 |
| IPA | Stout | 1 | 0.25 |
| Pils | IPA | 2 | 0.666666666666667 |
| Pils | Stout | 1 | 0.2 |
| Stout | Cider | 2 | 0.666666666666667 |
| Stout | IPA | 1 | 0.25 |
| Stout | Pils | 1 | 0.2 |
Each friend's closest match
Adamic-Adar, the best one for each: a friend shared with few others weighs more.
EVALUATE
VAR Links =
DATATABLE (
"From", STRING, "To", STRING,
{
{ "Ann", "Bo" }, { "Ann", "Cy" }, { "Bo", "Cy" }, { "Cy", "Di" },
{ "Di", "Ed" }, { "Ed", "Fay" }, { "Di", "Fay" }, { "Fay", "Gus" }
}
)
RETURN
NETWORK.SIMILARITY ( Links, [From], [To], "adamic-adar", 1 )
| Node | Other | Shared | Similarity |
|---|---|---|---|
| Ann | Cy | 1 | 1.44269504088896 |
| Bo | Cy | 1 | 1.44269504088896 |
| Cy | Ann | 1 | 1.44269504088896 |
| Di | Fay | 1 | 1.44269504088896 |
| Ed | Cy | 1 | 0.910239226626837 |
| Fay | Di | 1 | 1.44269504088896 |
| Gus | Di | 1 | 0.910239226626837 |
Only the close pairs
Every pair, but only those sharing at least two thirds of their neighbours (new in 0.3.77).
EVALUATE
VAR Baskets =
DATATABLE (
"Customer", STRING, "Product", STRING,
{
{ "Ola", "Pils" }, { "Ola", "IPA" }, { "Kari", "Pils" }, { "Kari", "IPA" }, { "Kari", "Stout" },
{ "Per", "Stout" }, { "Per", "Cider" }, { "Liv", "Cider" }, { "Liv", "Stout" }, { "Nils", "Pils" }
}
)
RETURN
NETWORK.SIMILARITY ( Baskets, [Customer], [Product], "jaccard", 0, 0.66 )
| Node | Other | Shared | Similarity |
|---|---|---|---|
| Cider | Stout | 2 | 0.666666666666667 |
| IPA | Pils | 2 | 0.666666666666667 |
| Kari | Ola | 2 | 0.666666666666667 |
| Liv | Per | 2 | 1 |
| Ola | Kari | 2 | 0.666666666666667 |
| Per | Liv | 2 | 1 |
| Pils | IPA | 2 | 0.666666666666667 |
| Stout | Cider | 2 | 0.666666666666667 |
Related functions
NETWORK.NODES, NETWORK.COMMUNITIES, NETWORK.PREDICT, FILTER.
NETWORK.SIMILARITY is OpenBI's own code: it calls no function of Open Graph, OpenBI's graph library. See the OAX network functions and Open Graph.