text_html_output_1.png
from sklearn.cluster import KMeans

from sklearn.feature_extraction.text import CountVectorizer

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import pandas as pd
df = pd.read_csv('/kaggle/input/midjourney-v5-prompts-and-links/MJ_Part3.csv')
df

df = df.drop(['AuthorID', 'Author', 'Date', 'Reactions', 'Attachments'], axis=1)
df

df = df.dropna()
df

df = df[df['Content'] != 'No Match']
df

from sklearn.feature_extraction.text import CountVectorizer
cv = CountVectorizer(max_features=5000, stop_words='english')

vectors = cv.fit_transform(df['Content']).toarray()
vectors

from sklearn.cluster import KMeans
num_clusters = 100
kmeans = KMeans(n_clusters=num_clusters)
kmeans.fit(vectors)
cluster_labels = kmeans.labels_
df['Cluster'] = cluster_labels
for cluster in range(num_clusters):
    prompts_in_cluster = df[df['Cluster'] == cluster]['Content'].values
    print(f'Cluster {cluster}:')
    for prompt in prompts_in_cluster:
        print(prompt)
    print()