Applies to: ✅Microsoft Fabric✅Azure Data Explorer✅Azure Monitor✅Microsoft Sentinel
値の類似性に基づいて文字列のセットをグループ化します。
このようなグループごとに、演算子は pattern、 count、および representativeを返します。
patternは、*文字がワイルドカードを表すグループを最もよく表します。
countはグループ内の値の数であり、representativeはグループ内の元の値の 1 つです。
Syntax
T|reduce [kind=ReduceKind] byExpr [with [threshold=Threshold] [,characters=Characters]]
Learn more about syntax conventions.
Parameters
| Name | タイプ | Required | Description |
|---|---|---|---|
| Expr | string |
✔️ | 削減する値。 |
| Threshold | real |
削減操作をトリガーするためにグループ化条件に一致するために必要な行の最小比率を決定する 0 ~ 1 の値。 既定値は 0.1 です。 しきい値パラメーターは、値をグループ化するために必要な類似性の最小レベルを決定します。 しきい値が小さいほど (0 に近い)、類似した値がグループ化され、グループが少なくなりますが、類似したグループが増えます。 しきい値を大きくすると (1 に近いほど)、必要な類似性が低くなり、結果として類似度の低いグループが増えます。 大きな入力には、小さなしきい値を設定することをお勧めします。 See Examples. |
|
| Characters | string |
用語間で区切られた文字の一覧。 既定値は、すべての非 ascii 数値です。 For examples, see Examples. | |
| ReduceKind | string |
有効な値は sourceのみです。
sourceが指定されている場合、演算子はPatternで集計するのではなく、テーブル内の既存の行にPattern列を追加します。 |
Returns
pattern、count、およびrepresentativeというタイトルのグループと列と同じ数の行を含むテーブル。
patternは、*文字がワイルドカードまたは任意の挿入文字列のプレースホルダーを表すグループを最もよく表します。
countはグループ内の値の数であり、representativeはグループ内の元の値の 1 つです。
たとえば、 reduce by city の結果には次のものが含まれます。
| Pattern | Count | Representative |
|---|---|---|
| San * | 5182 | San Bernard |
| Saint * | 2846 | Saint Lucy |
| Moscow | 3726 | Moscow |
| *-オン-* | 2730 | 1 対 1 |
| Paris | 2716 | Paris |
Examples
このセクションの例では、構文を使用して作業を開始する方法を示します。
The examples in this article use publicly available tables in the help cluster, such as the
StormEventstable in the Samples database.
The examples in this article use publicly available tables, such as the
Weathertable in the Weather analytics sample gallery. ワークスペース内のテーブルと一致するように、クエリ例のテーブル名を変更する必要がある場合があります。
次の例では、数値の範囲を生成し、連結された文字列とランダムな整数を含む新しい列を作成し、新しい列ごとに特定の削減パラメーターを使用して行をグループ化します。 しきい値は 0.001 に設定されています。これは、演算子が相互に非常に類似した値をグループ化することを意味します。
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"
Output
| Pattern | Count | Representative |
|---|---|---|
| MachineLearning* | 1000 | MachineLearningX4 |
次の例では、数値の範囲を生成し、連結された文字列とランダムな整数を含む新しい列を作成し、新しい列ごとに特定の削減パラメーターを使用して行をグループ化します。 しきい値は 0.9 に設定されています。つまり、演算子は値を厳密にグループ化し、より多くの分散を可能にします。
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"
Output
結果には、MyText 値が行の少なくとも 90% に表示されるグループのみが含まれます。
| Pattern | 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 |
If the Characters parameter is unspecified, by default the operator treats all non-alphanumeric characters (including spaces and punctuation) as term separators.
The following example shows how the reduce operator behaves when the Characters parameter isn't specified.
range x from 1 to 10 step 1 | project str = strcat("foo", "Z", tostring(x)) | reduce by str
Output
| Pattern | Count | Representative |
|---|---|---|
| others | 10 |
ただし、"Z" が区切り記号であることを指定すると、str の各値が 2 つの用語であるかのように foo と tostring(x)。
range x from 1 to 10 step 1 | project str = strcat("foo", "Z", tostring(x)) | reduce by str with characters="Z"
Output
| Pattern | Count | Representative |
|---|---|---|
| foo* | 10 | fooZ1 |
次の例は、reduce 演算子を "サニタイズ済み" 入力に適用する方法を示しています。この入力では、減らす前に列の GUID が置き換えられます。
トレース テーブルのいくつかのレコードから始めます。 次に、ランダムな GUID を含む [テキスト] 列を減らします。 ランダム GUID が reduce 操作を妨げるので、すべてを文字列 "GUID" に置き換えます。 次に、reduce 操作を実行します。 '-' または '_' 文字が埋め込まれた他の "準ランダム" 識別子がある場合は、文字を非用語ブレーカーとして扱います。
Trace
| take 10000
| extend Text = replace(@"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}", "GUID", Text)
| reduce by Text with characters="-_"
Related content
Note
reduce 演算子の実装は、主として『イベント ログのパターン検出のためのデータ クラスタリング アルゴリズム』 (Risto Vaarandi 著) に基づいています。