Unsupervised Learning


Clustering

K-Means Clustering

from sklearn.cluster import KMeans km = KMeans(n_clusters=3,init='k-means++') km = km.fit(X1) y_predict = km.predict(X2) print(km.interia_)


Other Clustering Algorithms

Hierarchical Agglomerative Clustering

import sklearn.cluster import AgglomerativeClustering agc = AgglomerativeClustering(n_clusters=3, affinity='euclidean', linkage='ward') agc = agc.fit(X) y_predict = agc.predict(Xx)

DBSCAN

from sklearn.cluster import DBSCAN db = DBSCAN(eps=3, min_samples=2) db.fit(X) # clusters clusters = db.labels_

There is no predict because of the nature of the algorithm. If we want new data, just call fit again and see labels for cluster assignment. Outliers are assigned -1.

Mean Shift

from sklearn.cluster import MeanShift ms = MeanShift(bandwidth=3) ms.fit(X) ms.predict(Xx)


Dimensionality Reduction at separate page .