OPSTIC聚类算法

from sklearn.cluster import OPTICS,cluster_optics_dbscan
from sklearn.datasets import make_blobs
import numpy as np
import matplotlib.pyplot as plt
x,y = make_blobs(n_samples=500,n_features=4)
clust = OPTICS(min_samples=50,max_eps=np.inf,cluster_method='dbscan',eps=4.5,xi=.05,min_cluster_size=0.05)
np_data = np.array(x)
data = clust.fit(np_data)
print(x)
# print(clust.ordering_)
reachablity = data.reachability_[clust.ordering_]
print(reachablity)
plt.subplot(2,2,1)
plt.plot(list(range(1,501)),reachablity,marker='.',markeredgewidth=3,linestyle='-')
print(data.labels_)
plt.subplot(2,2,2)
plt.scatter(np_data[:,0],np_data[:,1],c=data.labels_+1.5,linewidths=np.power(clust.labels_+1.5,2))
plt.show()

你可能感兴趣的:(python,numpy,机器学习)