gpt4 book ai didi

python - 为什么我得到 "Supported target types are: (' 二进制', 'multiclass' )。相反,得到 'continuous'。“错误?

转载 作者:行者123 更新时间:2023-11-30 09:03:38 24 4
gpt4 key购买 nike

我正在编写此代码并不断获取支持的目标类型为:(“二进制”、“多类”)。取而代之的是“连续”。无论我尝试什么都会出错。您看到我的代码中存在问题了吗?

df = pd.read_csv('drain.csv')
values = df.values
seed = 7
numpy.random.seed(seed)
X = df.iloc[:,:2]
Y = df.iloc[:,2:]
def create_model():
# create model
model = Sequential()
model.add(Dense(12, input_dim=8, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
# Compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
return model
model = KerasClassifier(build_fn=create_model, epochs=10, batch_size=10, verbose=0)
# evaluate using 10-fold cross validation
kfold = StratifiedKFold(n_splits=10, shuffle=True, random_state=seed)
results = cross_val_score(model, X, Y, cv=kfold)
print(results.mean())

最佳答案

您需要将 Y 变量转换为二进制,如下所示: https://github.com/keras-team/keras/blob/master/examples/mnist_mlp.py

# convert class vectors to binary class matrices
y_train = keras.utils.to_categorical(y_train, num_classes)
y_test = keras.utils.to_categorical(y_test, num_classes)

然后

history = model.fit(x_train, y_train,
batch_size=batch_size,
epochs=epochs,
verbose=1,
validation_data=(x_test, y_test))

您似乎忘记了转换为分类步骤。

关于python - 为什么我得到 "Supported target types are: (' 二进制', 'multiclass' )。相反,得到 'continuous'。“错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58585227/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com