我正在尝试使用来自yellowbrick库的KElbowVisualizer绘制KMeans平方和。代码在此之前运行良好,但是奇怪的是类型错误开始弹出,提示“ flip()缺少1个必需的位置参数:'axis。'。我有些想法,认为它可能与numpy版本有关,但无法弄清楚。我要运行的代码及其错误如下。
from sklearn.cluster import KMeans
from sklearn.datasets import make_blobs
from yellowbrick.cluster import KElbowVisualizer
# Generate synthetic dataset with 8 random clusters
X, y = make_blobs(n_samples=1000, n_features=12, centers=8, random_state=42)
# Instantiate the clustering model and visualizer
model = KMeans()
visualizer = KElbowVisualizer(model, k=(4,12))
visualizer.fit(X) # Fit the data to the visualizer
visualizer.show()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-6e34e2651568> in <module>
11 visualizer = KElbowVisualizer(model, k=(4,12))
12
---> 13 visualizer.fit(X) # Fit the data to the visualizer
14 visualizer.show()
/anaconda3/lib/python3.7/site-packages/yellowbrick/cluster/elbow.py in fit(self, X, y, **kwargs)
332 }.get(self.metric, {})
333 elbow_locator = KneeLocator(
--> 334 self.k_values_, self.k_scores_, **locator_kwargs
335 )
336 if elbow_locator.knee is None:
/anaconda3/lib/python3.7/site-packages/yellowbrick/utils/kneed.py in __init__(self, x, y, S, curve_nature, curve_direction)
108 self.y_normalized,
109 self.curve_direction,
--> 110 self.curve_nature,
111 )
112 # normalized difference curve
/anaconda3/lib/python3.7/site-packages/yellowbrick/utils/kneed.py in transform_xy(x, y, direction, curve)
164 # flip decreasing functions to increasing
165 if direction == "decreasing":
--> 166 y = np.flip(y)
167
168 if curve == "convex":
TypeError: flip() missing 1 required positional argument: 'axis'
答案 0 :(得分:0)
您尝试以下吗?
np.flip(y, axis=None)