text-clustering/text_clustering.py
def cluster_texts(texts, clusters=3):
    """ Transform texts to Tf-Idf coordinates and cluster texts using K-Means """
    vectorizer = TfidfVectorizer(tokenizer=process_text,
                                 stop_words=stopwords.words('english'),
                                 max_df=0.5,
                                 min_df=0.1,
                                 lowercase=True)
    tfidf_model = vectorizer.fit_transform(texts)
    print(tfidf_model)
    km_model = KMeans(n_clusters=clusters)
    km_model.fit(tfidf_model)

    clustering = collections.defaultdict(list)

    for idx, label in enumerate(km_model.labels_):
        clustering[label].append(idx)

    return clustering
 Transform texts to Tf-Idf coordinates and cluster texts using K-Means 
Transform texts to Tf-Idf coordinates and cluster texts using K-Means
Transform texts to Tf - Idf coordinates and cluster texts using K - Means
def cluster_texts(texts, clusters=3):
    vectorizer = TfidfVectorizer(tokenizer=process_text,
                                 stop_words=stopwords.words('english'),
                                 max_df=0.5,
                                 min_df=0.1,
                                 lowercase=True)
    tfidf_model = vectorizer.fit_transform(texts)
    print(tfidf_model)
    km_model = KMeans(n_clusters=clusters)
    km_model.fit(tfidf_model)
    clustering = collections.defaultdict(list)
    for idx, label in enumerate(km_model.labels_):
        clustering[label].append(idx)
    return clustering
def cluster_texts ( texts , clusters = 3 ) : vectorizer = TfidfVectorizer ( tokenizer = process_text , stop_words = stopwords . words ( 'english' ) , max_df = 0.5 , min_df = 0.1 , lowercase = True ) tfidf_model = vectorizer . fit_transform ( texts ) print ( tfidf_model ) km_model = KMeans ( n_clusters = clusters ) km_model . fit ( tfidf_model ) clustering = collections . defaultdict ( list ) for idx , label in enumerate ( km_model . labels_ ) : clustering [ label ] . append ( idx ) return clustering
Transform texts to Tf-Idf coordinates and cluster texts using K-Means
Transform texts to Tf - Idf coordinates and cluster texts using K - Means
""" Transform texts to Tf-Idf coordinates and cluster texts using K-Means """
texts
clusters