簡體   English   中英

sklearn.cluster.KMeans 得到“TypeError:__init__() 得到了一個意外的關鍵字參數‘n_jobs’”

[英]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).

資料來源: https://scikit-learn.org/0.24/modules/generated/sklearn.cluster.KMeans.html?highlight=kmeans#sklearn.cluster.KMeans

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM