简体   繁体   English

TypeError:__init__() 为straifiedkfold 的参数“n_splits”获得了多个值

[英]TypeError: __init__() got multiple values for argument 'n_splits' forstraifiedkfold

this is my imports这是我的进口

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import patches
from sklearn.mixture import GaussianMixture
from sklearn.model_selection import ShuffleSplit
from sklearn import mixture
from sklearn import datasets
from sklearn.model_selection import KFold
from sklearn.model_selection import StratifiedKFold
from sklearn import mixture




iris = datasets.load_iris()

was folds then change it to splits but error below appear是折叠然后将其更改为拆分但出现以下错误

indices = StratifiedKFold(iris.target, n_splits=5)

train_index, test_index = next(iter(indices))

X_train = iris.data[train_index]
y_train = iris.target[train_index]


X_test = iris.data[test_index]
y_test = iris.target[test_index]

error = TypeError: init () got multiple values for argument 'n_splits' error = TypeError: init () got multiple values for argument 'n_splits'

as per the documnentation , you first need to initialize your StratifiedKFold object with n_splits and then use the skf.get_n_splits method so your code becomes:根据文档,您首先需要使用 n_splits 初始化您的StratifiedKFold object ,然后使用skf.get_n_splits方法,以便您的代码变为:

skf = StratifiedKFold(n_splits=5)

X = iris.data
y = iris.target 
for train_index, test_index in skf.split(X, y):
    print("TRAIN:", train_index, "TEST:", test_index)
    X_train, X_test = X[train_index], X[test_index]
    y_train, y_test = y[train_index], y[test_index]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:__init __()为参数'n_splits'获取了多个值 - TypeError: __init__() got multiple values for argument 'n_splits' TypeError:__init__() 在癌症数据集中为参数“n_splits”获得了多个值 - TypeError: __init__() got multiple values for argument 'n_splits' in the cancer dataset “__init __()得到参数'n_splits'的多个值”与sklearn ShuffleSplit的错误 - “__init__() got multiple values for argument 'n_splits'” error with sklearn ShuffleSplit __init __()得到了意外的关键字参数'n_splits'错误 - __init__() got an unexpected keyword argument 'n_splits' ERROR SKLearn: TypeError: __init__() 得到了一个意外的关键字参数 n_splits - SKLearn: TypeError: __init__() got an unexpected keyword argument n_splits Python TypeError:__ init __()为参数'master'获取了多个值 - Python TypeError: __init__() got multiple values for argument 'master' TypeError:__init __()为关键字参数“ choices”获得了多个值 - TypeError: __init__() got multiple values for keyword argument 'choices' TypeError:“ __ init __()为关键字参数'name'获得了多个值” - TypeError: “__init__() got multiple values for keyword argument 'name'” TypeError: __init__() 为参数 'center' 获得了多个值 - TypeError: __init__() got multiple values for argument 'center' TypeError:__ init __()得到关键字参数'customer'的多个值 - TypeError: __init__() got multiple values for keyword argument 'customer'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM