Share via


reduce 運算子

根據值相似性將一組字串分組在一起。

針對每個這類群組,運算符會傳 pattern回、 countrepresentative。 最 pattern 能描述群組,其中 * 字元代表通配符。 count是群組中的值數目,而 representative 是群組中的其中一個原始值。

Syntax

T|reduce [kind=ReduceKind] byExpr [with [threshold=Threshold] [,characters=Characters]]

深入瞭解 語法慣例

參數

名稱 類型 必要 Description
Expr string ✔️ 要減少的值。
閾值 real 介於 0 和 1 之間的值,決定符合分組準則所需的最小數據列分數,以觸發縮減作業。 預設值為 0.1。

我們建議為大型輸入設定較小的閾值。 使用較小的臨界值時,較類似的值會分組在一起,因而產生較少但更類似的群組。 較大的臨界值需要較少的相似度,導致較不相似的群組。 請參閱範例
字元 string 在字詞之間分隔的字元清單。 預設值是每個非 ascii 數值字元。 如需範例,請參閱 Characters 參數的行為
ReduceKind string 唯一有效的值為 source。 如果 source 已指定 ,運算符會將數據 Pattern 行附加至數據表中的現有數據列,而不是由 Pattern匯總。

傳回

數據表,其中包含標題為、 count和 的群組和數據representativepattern數目一樣多的數據列。 最 pattern 能描述群組,其中 * 字元代表任意插入字串的通配符或佔位元。 count是群組中的值數目,而 representative 是群組中的其中一個原始值。

例如, reduce by city 的結果可能包括:

模式 Count Representative
San * 5182 San Bernard
Saint * 2846 Saint Lucy
Moscow 3726 Moscow
* -on- * 2730 一對一
Paris 2716 Paris

範例

小臨界值

range x from 1 to 1000 step 1
| project MyText = strcat("MachineLearningX", tostring(toint(rand(10))))
| reduce by MyText  with threshold=0.001 , characters = "X" 

輸出

模式 Count Representative
MachineLearning* 1000 MachineLearningX4

大型閾值

range x from 1 to 1000 step 1
| project MyText = strcat("MachineLearningX", tostring(toint(rand(10))))
| reduce by MyText  with threshold=0.9 , characters = "X" 

輸出

模式 Count Representative
MachineLearning* 177 MachineLearningX9
MachineLearning* 102 MachineLearningX0
MachineLearning* 106 MachineLearningX1
MachineLearning* 96 MachineLearningX6
MachineLearning* 110 MachineLearningX4
MachineLearning* 100 MachineLearningX3
MachineLearning* 99 MachineLearningX8
MachineLearning* 104 MachineLearningX7
MachineLearning* 106 MachineLearningX2

Characters 參數的行為

如果未指定 Characters 參數,則每個非 ascii 數位字元都會變成字詞分隔符。

range x from 1 to 10 step 1 | project str = strcat("foo", "Z", tostring(x)) | reduce by str

輸出

模式 Count Representative
別人 10

不過,如果您指定 「Z」 是分隔符,則就像中的每個 str 值都是 2 個字詞: footostring(x)

range x from 1 to 10 step 1 | project str = strcat("foo", "Z", tostring(x)) | reduce by str with characters="Z"

輸出

模式 Count Representative
Foo* 10 fooZ1

套用 reduce 至清理的輸入

下列範例示範如何將 reduce 運算子套用至「已處理」的輸入,其中資料行中的 GUID 會在縮減之前取代

// Start with a few records from the Trace table.
Trace | take 10000
// We will reduce the Text column which includes random GUIDs.
// As random GUIDs interfere with the reduce operation, replace them all
// by the string "GUID".
| extend Text=replace_regex(Text, @"[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}", @"GUID")
// Now perform the reduce. In case there are other "quasi-random" identifiers with embedded '-'
// or '_' characters in them, treat these as non-term-breakers.
| reduce by Text with characters="-_"

autocluster

注意

reduce 運算子的實作主要是以 Risto Vaarandi 撰寫的 A Data Clustering Algorithm for Mining Patterns From Event Logs 一文為基礎。