最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - getting a warning on k-means - Stack Overflow

programmeradmin0浏览0评论

I am running a k-means cluster analysis in python and am getting a warning.

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.
  

I have tried to set the environ variable

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

But the warnings don't go away, and it looks like the variable is not persistent (when i restart python, it's not there anymore) which got me searching through stackoverflow and found the following sites

answer

answer

answer

Bear in mind I am on the work PC and I have no admin rights. So my question are:

  1. What happens if I just ignore the warning and keep using k-means? The results look fine as it is but would not want to kick the can down the road.
  2. Is there any solution that doesn't involve admin rights or writing scripts (not that i am familiar with anyways)?

Since I am beginning to use python extensively and other modules with similar issues, I would like to tackle this problem sooner than later.

Thanks, Jung

I am running a k-means cluster analysis in python and am getting a warning.

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.
  

I have tried to set the environ variable

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

But the warnings don't go away, and it looks like the variable is not persistent (when i restart python, it's not there anymore) which got me searching through stackoverflow and found the following sites

answer

answer

answer

Bear in mind I am on the work PC and I have no admin rights. So my question are:

  1. What happens if I just ignore the warning and keep using k-means? The results look fine as it is but would not want to kick the can down the road.
  2. Is there any solution that doesn't involve admin rights or writing scripts (not that i am familiar with anyways)?

Since I am beginning to use python extensively and other modules with similar issues, I would like to tackle this problem sooner than later.

Thanks, Jung

Share asked Mar 5 at 16:51 Jung Hun KimJung Hun Kim 194 bronze badges 2
  • 1 Are you issuing os.environ[...] before or after your other imports? Make sure it's before so that if you're importing anything else. The variable goes away because it won't persist in the environment variables, you'd have to manually set that, but it would limit things to one thread for MKL, so might not want that for all applications. – Chrispresso Commented Mar 5 at 16:59
  • 1 maybe you should set it directly in system - it is the only method to presist it. In other situation you may try to run OMP_NUM_THREADS=1 directly in console and it should remeber it until you close console. You may also use it in the same line as you start script OMP_NUM_THREADS=1 python script.py (at least it can work on Linux) but this need to run everytime. Or you can create script which set variable and run code and always start this script to run your code. Eventually in code you can try to use standard module warning to hide this message. – furas Commented Mar 6 at 5:44
Add a comment  | 

1 Answer 1

Reset to default -1

You don't need admin rights to set user environment variables. Type 'env' into your start menu and look for a 'Edit environment variables for your account'. Add it in there. You will need to restart your shell/IDE/platform to make it available.

发布评论

评论列表(0)

  1. 暂无评论