Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Frequent Items sets

# Hello World program in Python
import collections
import itertools
from typing import List, Dict

def flatten_list(list2d: List[List[str]]) -> List[str]:
    return list(itertools.chain.from_iterable(list2d))
    
def frequent_items(list_of_tokens: List[List[str]], min_sup: int) -> Dict[str, int]:
    """
    fonction permettant de calculer les motifs fréquents
    """
    vocab_set = set(flatten_list(list_of_tokens))
    frequent_items = {}
    for item in vocab_set:
        count = 0
        for token in list_of_tokens:
            if item in token:
                count += 1
        if count >= min_sup:
            frequent_items[item] = count

    return frequent_items

TOKENS = [["client", "satisfait"], ["client", "fidéliter"]]

print(flatten_list(TOKENS))
print(frequent_items(TOKENS, 1))

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.