TypeError: __init__() got multiple values for argument 'n_splits'
时间: 2023-12-06 15:05:22 浏览: 161
这个错误通常是因为在实例化一个对象时,传递了多个同名的参数。例如:
```
from sklearn.model_selection import KFold
kf = KFold(n_splits=5, n_splits=10)
```
在这个例子中,KFold类的构造函数接受一个参数n_splits,但我们传递了两个同名的参数n_splits,因此会引发TypeError异常。要解决这个问题,我们需要检查代码并确保每个参数都只传递一次。
相关问题
TypeError: __init__() got multiple values for argument 'schema'
This error occurs when you pass the same argument multiple times to the `__init__` method of a class.
For example:
```
class MyClass:
def __init__(self, arg1, arg2, schema):
self.arg1 = arg1
self.arg2 = arg2
self.schema = schema
my_object = MyClass(arg1=1, arg2=2, schema='my_schema', schema='your_schema')
```
In the above code, we are passing the `schema` argument twice when creating an instance of `MyClass`. This will result in the `TypeError: __init__() got multiple values for argument 'schema'`.
To fix this error, make sure to pass all arguments only once:
```
my_object = MyClass(arg1=1, arg2=2, schema='my_schema')
```
TypeError: __init__() got multiple values for argument 'filters'
This error occurs when the `__init__()` method of a class is called with multiple values for the same argument.
For example, if you have a class `MyClass` with an `__init__()` method that takes a `filters` argument:
```
class MyClass:
def __init__(self, filters):
self.filters = filters
```
And you create an instance of this class and pass multiple values for `filters`:
```
my_instance = MyClass(filters='value1', filters='value2')
```
You will get the `TypeError: __init__() got multiple values for argument 'filters'` error.
To fix this error, make sure that you are only passing one value for each argument in the `__init__()` method. In the above example, you could pass a list of values for `filters` instead:
```
my_instance = MyClass(filters=['value1', 'value2'])
```
阅读全文