T | evaluate basket()
Basket finds all frequent patterns of discrete attributes (dimensions) in the data. It then returns the frequent patterns that passed the frequency threshold in the original query. Basket is guaranteed to find every frequent pattern in the data, but isn't guaranteed to have polynomial runtime. The runtime of the query is linear in the number of rows, but it might be exponential in the number of columns (dimensions). Basket is based on the Apriori algorithm originally developed for basket analysis data mining.
T | evaluate basket( arguments
Basket returns all frequent patterns appearing above the ratio threshold of the rows. The default threshold is 0.05. Each pattern is represented by a row in the results.
The first column is the segment ID. The next two columns are the count and percentage of rows, from the original query, that are captured by the pattern. The remaining columns are from the original query. Their value is either a specific value from the column or a wildcard value, which is by default null, meaning a variable value.
Arguments (all optional)
T | evaluate basket([Threshold, WeightColumn, MaxDimensions, CustomWildcard, CustomWildcard, ...]
All arguments are optional, but they must be ordered as above. To indicate that the default value should be used, use the string tilde value - '~'. See examples below.
Threshold - 0.015 < double < 1 [default: 0.05]
Sets the minimal ratio of the rows to be considered frequent. Patterns with a smaller ratio won't be returned.
T | evaluate basket(0.02)
WeightColumn - column_name
Considers each row in the input according to the specified weight. By default, each row has a weight of '1'. The argument must be a name of a numeric column, such as int, long, real. A common use of a weight column, is to take into account sampling or bucketing/aggregation of the data that is already embedded into each row.
T | evaluate basket('~', sample_Count)
MaxDimensions - 1 < int [default: 5]
Sets the maximal number of uncorrelated dimensions per basket, limited by default, to minimize the query runtime.
T | evaluate basket('~', '~', 3)
CustomWildcard - "any_value_per_type"
Sets the wildcard value for a specific type in the result table that will indicate that the current pattern doesn't have a restriction on this column. Default is null. The default for a string is an empty string. If the default is a good value in the data, a different wildcard value should be used, such as
T | evaluate basket('~', '~', '~', '*', int(-1), double(-1), long(0), datetime(1900-1-1))
StormEvents | where monthofyear(StartTime) == 5 | extend Damage = iff(DamageCrops + DamageProperty > 0 , "YES" , "NO") | project State, EventType, Damage, DamageCrops | evaluate basket(0.2)
Example with custom wildcards
StormEvents | where monthofyear(StartTime) == 5 | extend Damage = iff(DamageCrops + DamageProperty > 0 , "YES" , "NO") | project State, EventType, Damage, DamageCrops | evaluate basket(0.2, '~', '~', '*', int(-1))