我正在尝试使用库yellowbrick中的KElbowVisualizer绘制KMeans平方和。代码之前运行良好,但奇怪的是,类型错误开始弹出,显示"flip()缺少1个必需的位置参数:‘轴’。“我有一些想法,它可能与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'发布于 2020-02-03 22:15:38
你有没有尝试过下面的方法?
np.flip(y, axis=None)https://stackoverflow.com/questions/60040491
复制相似问题