import numpy as np
from sklearn.datasets import make_classification
from sklearn.cluster import KMeans
X, y = make_classification(n_samples=1000,
n_features=4,
n_informative=3,
n_redundant=0,
n_repeated=0,
n_classes=2,
random_state=0,
shuffle=False)
km = KMeans(n_clusters=3).fit(X)
result = permutation_importance(km, X, y, scoring='homogeneity_score', n_repeats=10, random_state=0, n_jobs=-1)
result在真正的问题中,我没有y(真实标签),我尝试使用y=None来使其成为一种无监督学习。但它不起作用。我得到了:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-72-81045ae9cb66> in <module>()
----> 1 result = permutation_importance(km, X, y=None, scoring='homogeneity_score', n_repeats=10, random_state=0, n_jobs=-1)
5 frames
/usr/local/lib/python3.6/dist-packages/sklearn/metrics/cluster/_supervised.py in check_clusterings(labels_true, labels_pred)
53 if labels_true.ndim != 1:
54 raise ValueError(
---> 55 "labels_true must be 1D: shape is %r" % (labels_true.shape,))
56 if labels_pred.ndim != 1:
57 raise ValueError(
ValueError: labels_true must be 1D: shape is ()有谁知道如何在没有真正标签的情况下实现?
发布于 2019-12-07 16:41:41
首先,证明k-means对于特征的排列是不变的,这是很容易的。因为和是排列不变的。
如果你仍然想进行实验,可以尝试使用一个0数组作为y?
https://stackoverflow.com/questions/59219819
复制相似问题