运行此函数时
def evaluate_performance(self, data):
data = np.array(data)
print(data.shape[0])
if self.cluster_method == 'kmeans':
predicted_labels = self.cluster_model.predict(data)
score = silhouette_score(data, predicted_labels)
print(f"Silhouette score: {score}")
elif self.cluster_method == 'isolation_forest':
predicted_scores = self.cluster_model.score_samples(data)
score = silhouette_score(data, predicted_scores)
print(f"Silhouette score: {score}")
我得到这个错误AttributeError: 'list' object has no attribute 'shape'
在一个单独的函数中从csv文件访问数据,该函数返回pandas Dataframe 的values属性。
我使用print语句来验证.predict
的输入数据是一个numpy数组,甚至得到了data.shape
的值,但我似乎无法弄清楚为什么这个错误仍然存在。
1条答案
按热度按时间tjjdgumg1#
我没有看到你的类的方法,但是Silhouette reference是这样定义的:
因此,第一个条件看起来不错,但第二个条件包括
把分数放在这里很奇怪,考虑用标签代替它。
Hope这有帮助