Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Examples
-----------
For usage examples, please see
http://rasbt.github.io/mlxtend/user_guide/frequent_patterns/apriori/
"""
out = (np.sum(_x, axis=0) / _n_rows)
return np.array(out).reshape(-1)
if min_support <= 0.:
raise ValueError('`min_support` must be a positive '
'number within the interval `(0, 1]`. '
'Got %s.' % min_support)
fpc.valid_input_check(df)
# sparse attribute exists for both deprecated SparseDataFrame and
# DataFrame with SparseArray (pandas >= 0.24); to_coo attribute
# exists only for the former, thus it is checked first to distinguish
# between SparseDataFrame and DataFrame with SparseArray.
if hasattr(df, "to_coo"):
# SparseDataFrame with pandas < 0.24
if df.size == 0:
X = df.values
else:
X = df.to_coo().tocsc()
is_sparse = True
elif hasattr(df, "sparse"):
# DataFrame with SparseArray (pandas >= 0.24)
if df.size == 0:
X = df.values
verbose : int (default: 0)
Shows the stages of conditional tree generation.
Returns
-----------
pandas DataFrame with columns ['support', 'itemsets'] of all maximal
itemsets that are >= `min_support` and < than `max_len`
(if `max_len` is not None).
Each itemset in the 'itemsets' column is of type `frozenset`,
which is a Python built-in type that behaves similarly to
sets except that it is immutable
(For more info, see
https://docs.python.org/3.6/library/stdtypes.html#frozenset).
"""
fpc.valid_input_check(df)
if min_support <= 0.:
raise ValueError('`min_support` must be a positive '
'number within the interval `(0, 1]`. '
'Got %s.' % min_support)
colname_map = None
if use_colnames:
colname_map = {idx: item for idx, item in enumerate(df.columns)}
tree, rank = fpc.setup_fptree(df, min_support)
minsup = math.ceil(min_support * len(df.values)) # min support as count
generator = fpmax_step(tree, minsup, MFITree(rank),
colname_map, max_len, verbose)
verbose : int (default: 0)
Shows the stages of conditional tree generation.
Returns
-----------
pandas DataFrame with columns ['support', 'itemsets'] of all itemsets
that are >= `min_support` and < than `max_len`
(if `max_len` is not None).
Each itemset in the 'itemsets' column is of type `frozenset`,
which is a Python built-in type that behaves similarly to
sets except that it is immutable
(For more info, see
https://docs.python.org/3.6/library/stdtypes.html#frozenset).
"""
fpc.valid_input_check(df)
if min_support <= 0.:
raise ValueError('`min_support` must be a positive '
'number within the interval `(0, 1]`. '
'Got %s.' % min_support)
colname_map = None
if use_colnames:
colname_map = {idx: item for idx, item in enumerate(df.columns)}
tree, _ = fpc.setup_fptree(df, min_support)
minsup = math.ceil(min_support * len(df.index)) # min support as count
generator = fpg_step(tree, minsup, colname_map, max_len, verbose)
return fpc.generate_itemsets(generator, len(df.index), colname_map)