2024-05-15 21:28:26 发布
网友
我有一个数据框,其中包含来自不同生产站和生产线的产品ID和传感器以及值(1:产品通过传感器/或0:产品和传感器之间没有关系)。 以下是数据帧的一部分:
我想使用一种聚类方法,可以根据流程(传感器)对产品系列中的产品进行聚类
谢谢你的帮助
由于没有标签,我们需要一种无监督的聚类方法
例如Kmeans。下面我提供一个例子
Kmeans
import numpy as np np.random.seed(0) from sklearn.cluster import KMeans # build fake data with only 0/1 values in the features X = np.ones((100,10)) random_indices_rows = np.random.randint(1,100,50) X[random_indices_rows]=0 print(X.shape) #(100, 10) # 100 samples and 10 variables/sensors # the clustering model kmeans = KMeans(n_clusters=2, random_state=0).fit(X) kmeans.labels_ print(kmeans.labels_) #array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, # 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, # 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, # 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, # 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int32)
由于没有标签,我们需要一种无监督的聚类方法
例如
Kmeans
。下面我提供一个例子相关问题 更多 >
编程相关推荐