简体   繁体   中英

sklearn.cluster.KMeans got "TypeError: __init__() got an unexpected keyword argument 'n_jobs'"

This error is cause due to following line

model = KMeans(n_clusters = k, n_jobs=8, max_iter = iteration). 

And my sklearn version is 1.0.1. I remember the sklearn.cluster.KMeans has n_jobs parameter. Does the sklearn.cluster.KMeans have no parameter of n-jobs after updating?

If you search for "sklearn kmeans", then the first result will be the official documentation page .

On that page, the first thing is the prototype, with the arguments and their default values:

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')

From where it is apparent that there is no argument called n_jobs .

There used to be an argument called n_jobs , but it was deprecated in version 0.23, and is now removed: sklearn (0.24).cluster.KMeans

n_jobs input argument has been deprecated after 0.23 version. In the latest version, there is no such input argument.

Currently, it uses all cores by default. If you want to use a specific number of cores, you can set the OMP_NUM_THREADS environment variable (see details) or use the threadpoolctl package. Source

From the documentation:

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).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM