TypeError:split()接受3到4个位置参数,但给出了5个

2024-04-26 12:30:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我用python实现了数据集的k-fold交叉验证。但是,我一直得到以下错误。在

TypeError: split() takes from 3 to 4 positional arguments but 5 were given

我确实通读了关于类似问题的问题,其中提到将self作为方法的第一个参数可以解决这个问题。但是,我不确定如何在处理split函数时添加self。在

在这方面的任何建议都将不胜感激。在

代码

X_train_pad_1 = triple_pad[:,0:4]
X_train_psl_1 = stv[:,0]
y_train_1 = truth[:,]
X_test_pad_1 = triple_pad[:,4]
X_test_psl_1 = stv[:,0]
Y_test_1 = truth[:,]
kfold = StratifiedKFold(n_splits=5, shuffle=True, random_state=seed)

for [X_train_pad,X_train_psl], y_train, [X_test_pad, X_test_psl],y_test in kfold.split([X_train_pad_1,X_train_psl_1], y_train_1, [X_test_pad_1, X_test_psl_1],y_test_1):

    input1 = layers.Input(shape=(max_length,))
    embedding = layers.Embedding(vocab_size, EMBEDDING_DIM, input_length=max_length)(input1)
    pooling = GRU(units=64, dropout=drp, recurrent_dropout=0.2)(embedding)

    input2 = layers.Input(shape=(1,))
    concat = layers.Concatenate(axis=-1)([pooling, input2])

    out = layers.Dense(1, activation='sigmoid')(concat)

    model = models.Model(inputs=[input1, input2], outputs=[out])
    model.compile(optimizer=optm, loss=los, metrics=['accuracy'])
    print(model.summary())

    history = model.fit([X_train_pad, X_train_psl], y_train, batch_size=btsize, epochs=ep,
    validation_data=([X_test_pad, X_test_psl], y_test), verbose=2)

    y_pred = (model.predict(x=[X_test_pad, X_test_psl]) > 0.1).astype(np.int32)

Tags: testselfmodellayerstrainlengthsplittriple