【问题标题】:kmeans cluster Newbiekmeans集群新手
【发布时间】:2020-11-19 08:50:44
【问题描述】:

我是 Python 新手,正在运行一个集群介绍演示。但是,代码在某一时刻卡住了,我希望有人能帮我解决这个问题。

    # Import the library
from sklearn.cluster import KMeans# To make sure our work becomes reproducible
np.random.seed(42)inertia = []# Iterating the process
for i in range(2, 10):
  # Instantiate the model
    model = KMeans(n_clusters=i)
  # Fit The Model
    model.fit(X_transformed)
  # Extract the error of the model
    inertia.append(model.inertia_)# Visualize the model
sns.pointplot(x=list(range(2, 10)), y=inertia)
plt.title('SSE on K-Means based on # of clusters')
plt.show()

这是我收到的错误消息:

      File "<ipython-input-32-95dac55492e9>", line 3
    np.random.seed(42)inertia = []# Iterating the process
                            ^
SyntaxError: invalid syntax

非常感谢

【问题讨论】:

  • Inertia = [] 应该换行

标签: python numpy k-means inertiajs


【解决方案1】:

惯性应该是换行

from sklearn.cluster import KMeans# To make sure our work becomes reproducible
np.random.seed(42)
inertia = []# Iterating the process

【讨论】:

    猜你喜欢
    • 2017-06-01
    • 2020-11-21
    • 1970-01-01
    • 2021-05-02
    • 2017-05-25
    • 1970-01-01
    • 2019-04-04
    • 1970-01-01
    • 2016-11-09
    相关资源
    最近更新 更多