Clustering Techniques
Clustering techniques are tested here to see their accuracy in terms of output.
Python program:
>>> clf52= cluster.AffinityPropagation()
>>> clf53= cluster.MeanShift()
>>> clf54= cluster.SpectralClustering()
>>> clf55= cluster.AgglomerativeClustering()
>>> clf56= cluster.DBSCAN()
>>> clf57= cluster.Birch()
>>> from sklearn import mixture
>>> clf58= cluster.GaussianMixture()
//Plotting the output//
>>> for clf in [clf51, clf52, clf53, clf57, clf58]:
... clf.fit(x, y)
... x_min, x_max = x[:, 0].min() -1, x[:, 0].max() +1
... y_min, y_max = x[:, 1].min() -1, x[:, 1].max() +1
... xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
... z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
... z = z.reshape(xx.shape)
... plt.figure()
... plt.pcolormesh(xx, yy, z, cmap=cmap_light)
... plt.scatter(x[:, 0], x[:, 1], c=y, cmap=cmap_bold, edgecolor='k', s=24)
... plt.xlim(xx.min(), xx.max())
... plt.ylim(yy.min(), yy.max())
... plt.title("Regressor (clf='%s')" %(clf))
...
Output:
Clustering techniques are tested here to see their accuracy in terms of output.
Python program:
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from matplotlib.colors import ListedColormap
>>> from sklearn import neighbors, datasets
>>> n_neighbors = 24
>>> iris = datasets.load_iris()
>>> x = iris.data[:, :2]
>>> y = iris.target
>>> h = .02
>>> cmap_bold = ListedColormap(['firebrick', 'lime', 'blue'])
>>> cmap_light = ListedColormap(['pink', 'lightgreen', 'paleturquoise'])
//Defining different clustering techniques//
>>> clf51= cluster.KMeans()>>> clf52= cluster.AffinityPropagation()
>>> clf53= cluster.MeanShift()
>>> clf54= cluster.SpectralClustering()
>>> clf55= cluster.AgglomerativeClustering()
>>> clf56= cluster.DBSCAN()
>>> clf57= cluster.Birch()
>>> from sklearn import mixture
>>> clf58= cluster.GaussianMixture()
//Plotting the output//
>>> for clf in [clf51, clf52, clf53, clf57, clf58]:
... clf.fit(x, y)
... x_min, x_max = x[:, 0].min() -1, x[:, 0].max() +1
... y_min, y_max = x[:, 1].min() -1, x[:, 1].max() +1
... xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
... z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
... z = z.reshape(xx.shape)
... plt.figure()
... plt.pcolormesh(xx, yy, z, cmap=cmap_light)
... plt.scatter(x[:, 0], x[:, 1], c=y, cmap=cmap_bold, edgecolor='k', s=24)
... plt.xlim(xx.min(), xx.max())
... plt.ylim(yy.min(), yy.max())
... plt.title("Regressor (clf='%s')" %(clf))
...
Output:
No comments:
Post a Comment