__init__() got an unexpected keyword argument 'n_jobs'啥错误
时间: 2023-10-02 19:10:22 浏览: 47
这个错误通常发生在使用不支持 `n_jobs` 参数的函数时,如下面的例子:
```python
from sklearn.linear_model import LogisticRegression
clf = LogisticRegression(n_jobs=-1)
```
这里使用了 `LogisticRegression` 函数,并尝试使用 `n_jobs` 参数来并行计算,但是 `LogisticRegression` 函数并不支持 `n_jobs` 参数,因此会抛出 `TypeError: __init__() got an unexpected keyword argument 'n_jobs'` 错误。
要解决这个问题,可以使用支持 `n_jobs` 参数的函数,或者去掉不支持 `n_jobs` 参数的函数中的 `n_jobs` 参数。如果需要并行计算,可以考虑使用其他支持并行计算的库,如 `joblib` 或 `multiprocessing`。
相关问题
__init__() got an unexpected keyword argument 'n_jobs
This error message is raised when the `__init__()` method of a class is called with an unexpected keyword argument `n_jobs`. This means that the class does not expect to receive the `n_jobs` argument, or it expects it to have a different name.
The `n_jobs` argument is often used in scikit-learn to specify the number of CPU cores to use for parallel processing. If you are encountering this error while using scikit-learn, make sure that you are passing the `n_jobs` argument to a method that expects it, and that you are passing it with the correct name.
If you are encountering this error with your own code, check the documentation or source code of the class you are using to see if it supports the `n_jobs` argument. If it does not, consider using a different class or library that does support parallel processing.
__init__() got an unexpected keyword argument 'n_jobs'
This error message suggests that the function or method you are trying to run does not recognize the parameter `n_jobs`. This parameter is often used to specify the number of parallel jobs to use for computation.
There are a few possible explanations for this error:
1. The code you are running does not support parallel processing and does not have a `n_jobs` parameter. In this case, you would need to modify the code to enable parallel processing or remove the `n_jobs` parameter.
2. The version of the library you are using does not support `n_jobs`. In this case, you may need to update the library to a newer version.
3. There is a typo or other mistake in your code that is causing the error. Double-check your code to make sure that you are passing the `n_jobs` parameter correctly and that it is spelled correctly.
Without more information about the specific code and library you are working with, it is difficult to provide a more specific solution.