Python 中的 Kmeans 问题

问题描述 投票:0回答:1

我正在分析一些神经数据,并想使用 Kmeans 将神经元的真实尖峰和噪声聚类为两个单独的簇。我这里有一个候选数据的测试数组,我想给出 K 均值。

这是我的代码:

import pickle
from sklearn.cluster import KMeans

fileName = 'test_array.pickle'

with open(fileName, 'rb') as file:
    output = pickle.load(file)
    print('Decomposition successful')

    # Initialize KMeans with 2 clusters (spikes and noise)
    kmeans = KMeans(n_clusters=2, init='k-means++', n_init=1, verbose=1)
    kmeans.fit(output.reshape(-1,1))
    print('K means works')

但是,当我应用Kmeans时,它似乎没有跑通它。它不会抛出任何特定错误,但会给出此警告:Intel MKL 警告:仅支持处理器的 Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) 已被弃用。英特尔 oneAPI 数学内核库 2025.0 将需要英特尔(R) 高级矢量扩展(英特尔(R) AVX)指令。

我有 M1 Macbook Pro(我读过它会导致有时抛出此警告......),但除此之外我不确定具体出了什么问题,我将不胜感激一些帮助和建议!预先感谢,这是一个测试代码,以及 pickle 测试数组的链接

https://drive.google.com/file/d/19USY6Sl07Cw4zU0qIUvdOjQIq748OIHf/view?usp=sharing

添加错误语句,例如值,内存错误

python numpy scikit-learn
1个回答
0
投票

我无法重现你的结果。

在我的电脑中它正确完成

Decomposition successful
Initialization complete
Iteration 0, inertia 1.36551392942632e+21.
Iteration 1, inertia 1.3408355122381565e+21.
Converged at iteration 1: center shift 22594703677792.88 within tolerance 385794820884420.4.
K means works

在您提到的一条评论中

it doesn't give the kmeans variable in my debugger output

这意味着如果您在调试模式下运行,可能有一个断点会中断执行。

尝试以下操作:

  • 从控制台运行代码。

  • 确保在调试模式下运行时没有断点。

© www.soinside.com 2019 - 2024. All rights reserved.