使用KMeans拟合数据的时候出现警告You can avoid it by setting the environment variable OMP_NUM_THREADS=2

问题遇到的现象和发生背景

使用KMeans拟合数据的时候出现警告。由于可能是数据量太大,然后出现这个情况,但是数据量很少的时候也会出现这个警告。

运行结果及报错内容
KMeans is known to have a memory leak on Windows with MKL, when there are less chunks than available threads. You can avoid it by setting the environment variable OMP_NUM_THREADS=2.

UserWarning: KMeans is known to have a memory leak on Windows with MKL, when there are less chunks than available threads. You can avoid it by setting the environment variable OMP_NUM_THREADS=1.
我想要达到的结果

请问我该如何消除警告,并解决这个提示的内存泄露。

UserWarning: KMeans is known to have a memory leak on Windows with MKL, when there are less chunks than available threads.** You can avoid it by setting the environment variable OMP_NUM_THREADS=1.**
根据这个报错的提示,你可以尝试 setting the environment variable OMP_NUM_THREADS=1.
即,在py文件的开头添加

import os
os.environ["OMP_NUM_THREADS"] = '1'

该解决方法来自:https://stackoverflow.com/questions/69596239/how-to-avoid-memory-leak-when-dealing-with-kmeans-for-example-in-this-code-i-am