Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- # Create Data
- Rank = ["High", "Low", "High", "Low", "Low", "High"]
- Topic = ["SE", "SE", "ML", "DM", "ML", "SE"]
- conferences = pd.DataFrame({"Rank": Rank, "Topic": Topic})
- print(conferences)
- print()
- # kmedoids
- # Not 'pip install sklearn_extra' ---> Try this: pip install scikit-learn-extra
- from sklearn_extra.cluster import KMedoids
- from sklearn.preprocessing import OneHotEncoder
- encoder = OneHotEncoder(handle_unknown="ignore", sparse=False)
- encoder = encoder.fit(conferences)
- conferences = encoder.transform(conferences)
- kmedoids = KMedoids(n_clusters=3, method="pam").fit(conferences)
- # Displays
- print("Medoids: ")
- print(kmedoids.cluster_centers_)
- print("Labels: ")
- print(kmedoids.labels_)
- # print(conferences.loc[kmedoids.medoid_indices_, :])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement