![](/img/trans.png)
[英]TypeError: __init__() got an unexpected keyword argument 'n_jobs' and n_clusters
[英]sklearn.cluster.KMeans got "TypeError: __init__() got an unexpected keyword argument 'n_jobs'"
此错误是由于以下行引起的
model = KMeans(n_clusters = k, n_jobs=8, max_iter = iteration).
而我的 sklearn 版本是 1.0.1。 我记得 sklearn.cluster.KMeans 有 n_jobs 参数。 sklearn.cluster.KMeans 更新后是否没有 n-jobs 参数?
如果您搜索“sklearn kmeans”,那么第一个结果将是官方文档页面。
在那个页面上,第一件事是原型,带有 arguments 及其默认值:
sklearn.cluster.KMeans(n_clusters=8, *, init='k-means++', n_init=10, max_iter=300, tol=0.0001, verbose=0, random_state=None, copy_x=True, algorithm='auto')
从那里很明显没有称为n_jobs
的参数。
曾经有一个名为n_jobs
的参数,但在 0.23 版中已弃用,现在已删除: sklearn (0.24).cluster.KMeans
n_jobs
输入参数在 0.23 版本后已被弃用。 在最新版本中,没有这样的输入参数。
目前,它默认使用所有内核。 如果要使用特定数量的内核,可以设置 OMP_NUM_THREADS 环境变量(请参阅详细信息)或使用 threadpoolctl package。 资源
从文档中:
n_jobsint, default=None
The number of OpenMP threads to use for the computation. Parallelism is sample-wise on the main cython loop which assigns each sample to its closest center.
None or -1 means using all processors.
Deprecated since version 0.23: n_jobs was deprecated in version 0.23 and will be removed in 1.0 (renaming of 0.25).
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.