ml-finance-python
python scripts for finance machine learning
git clone https://9o.is/git/ml-finance-python.git
partitioning_around_medoids.py
(540B)
1 from sklearn import datasets
2 import numpy as np
3
4 # Import helper functions
5 from mlfromscratch.utils import Plot
6 from mlfromscratch.unsupervised_learning import PAM
7
8 def main():
9 # Load the dataset
10 X, y = datasets.make_blobs()
11
12 # Cluster the data using K-Medoids
13 clf = PAM(k=3)
14 y_pred = clf.predict(X)
15
16 # Project the data onto the 2 primary principal components
17 p = Plot()
18 p.plot_in_2d(X, y_pred, title="PAM Clustering")
19 p.plot_in_2d(X, y, title="Actual Clustering")
20
21
22 if __name__ == "__main__":
23 main()