| title | description | ms.reviewer | ms.topic | ms.date |
|---|---|---|---|---|
series_cosine_similarity() |
This article describes series_cosine_similarity(). |
adieldar |
reference |
08/11/2024 |
[!INCLUDE applies] [!INCLUDE fabric] [!INCLUDE azure-data-explorer] [!INCLUDE monitor] [!INCLUDE sentinel]
Calculate the cosine similarity of two numerical vectors.
The function series_cosine_similarity() takes two numeric series as input, and calculates their cosine similarity.
series_cosine_similarity(series1, series2, [*magnitude1, [*magnitude2]])
[!INCLUDE syntax-conventions-note]
| Name | Type | Required | Description |
|---|---|---|---|
| series1, series2 | dynamic |
✔️ | Input arrays with numeric data. |
| magnitude1, magnitude2 | real |
Optional magnitude of the first and the second vectors respectively. The magnitude is the square root of the dot product of the vector with itself. If the magnitude isn't provided, it will be calculated. |
Returns a value of type real whose value is the cosine similarity of series1 with series2.
In case both series length isn't equal, the longer series will be truncated to the length of the shorter one.
Any non-numeric element of the input series will be ignored.
Note
If one or both input arrays are empty, the result will be null.
[!INCLUDE optimization-note]
[!div class="nextstepaction"] Run the query
datatable(s1:dynamic, s2:dynamic)
[
dynamic([0.1,0.2,0.1,0.2]), dynamic([0.11,0.2,0.11,0.21]),
dynamic([0.1,0.2,0.1,0.2]), dynamic([1,2,3,4]),
]
| extend cosine_similarity=series_cosine_similarity(s1, s2)| s1 | s2 | cosine_similarity |
|---|---|---|
| [0.1,0.2,0.1,0.2] | [0.11,0.2,0.11,0.21] | 0.99935343825504 |
| [0.1,0.2,0.1,0.2] | [1,2,3,4] | 0.923760430703401 |