问题描述:
使用如下语句进行库的调用时,发现k_means_
不存在,但是你确定有与此相关的,可能由于版本的原因名字有所更改
from sklearn.cluster.k_means_ import k_means
可以参考使用如下语句进行看
import sklearn.cluster
print(dir(sklearn.cluster))
['AffinityPropagation', 'AgglomerativeClustering', 'Birch', 'BisectingKMeans', 'DBSCAN', 'FeatureAgglomeration', 'HDBSCAN', 'KMeans', 'MeanShift', 'MiniBatchKMeans', 'OPTICS', 'SpectralBiclustering', 'SpectralClustering', 'SpectralCoclustering', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_affinity_propagation', '_agglomerative', '_bicluster', '_birch', '_bisect_k_means', '_dbscan', '_dbscan_inner', '_feature_agglomeration', '_hdbscan', '_hierarchical_fast', '_k_means_common', '_k_means_elkan', '_k_means_lloyd', '_k_means_minibatch', '_kmeans', '_mean_shift', '_optics', '_spectral', 'affinity_propagation', 'cluster_optics_dbscan', 'cluster_optics_xi', 'compute_optics_graph', 'dbscan', 'estimate_bandwidth', 'get_bin_seeds', 'k_means', 'kmeans_plusplus', 'linkage_tree', 'mean_shift', 'spectral_clustering', 'ward_tree']
在里面找到目标库的名字
from sklearn.cluster._kmeans import k_means