OpenBI Docs Buy

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>] )
ParameterTypeDescription
linksTableThe rows that make the network, one link a row: a table of the model or a table expression, as the filters leave it.
fromExpression
evaluated for each row
One end of each row's link, such as a payer, a customer or a place.
toExpression
evaluated for each row
The other end of each row's link.
methodText
optional
"jaccard" (when left out), "dice", "cosine" or "adamic-adar".
topWhole number
optional
How many of each node's most similar nodes are kept: 10 when left out, 0 for every pair.
thresholdNumber
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]
NodeOtherSharedSimilarity
CiderStout20.666666666666667
IPAPils20.666666666666667
IPAStout10.25
PilsIPA20.666666666666667
PilsStout10.2
StoutCider20.666666666666667
StoutIPA10.25
StoutPils10.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 )
NodeOtherSharedSimilarity
AnnCy11.44269504088896
BoCy11.44269504088896
CyAnn11.44269504088896
DiFay11.44269504088896
EdCy10.910239226626837
FayDi11.44269504088896
GusDi10.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 )
NodeOtherSharedSimilarity
CiderStout20.666666666666667
IPAPils20.666666666666667
KariOla20.666666666666667
LivPer21
OlaKari20.666666666666667
PerLiv21
PilsIPA20.666666666666667
StoutCider20.666666666666667

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.

Last updated · OpenBI Studio 0.3.78