该错误通常会在使用Auto-Keras库的StratifiedKFold进行交叉验证时出现。此问题的原因是划分数据时刚好有一种分类标签在某些折叠中没有观测到,因此会引发NumPy数组值错误。
解决此问题的方法是使用StratifiedKFold的另一个参数shuffle=True,它将会在每次交叉验证之前随机打乱训练数据。以下是使用shuffle=True进行StratifiedKFold的代码示例:
import numpy as np
from sklearn.model_selection import StratifiedKFold
from autokeras import StructuredDataClassifier
data = np.loadtxt('data.csv', delimiter=',')
X = data[:, :-1]
y = data[:, -1]
skf = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
for train_index, test_index in skf.split(X, y):
x_train, x_test = X[train_index], X[test_index]
y_train, y_test = y[train_index], y[test_index]
clf = StructuredDataClassifier(max_trials=10)
clf.fit(x_train, y_train)
clf.evaluate(x_test, y_test)
上述示例中,使用Shuffle=True参数轮换训练集和测试集,以随机化数据集的顺序并解决NumPy数组值错误。
上一篇:Auto-GTP无法连接到简单的FTP,尽管我输入了凭据,它仍无法使用。
下一篇:Auto-Layout,layoutconstraintsproducingpuzzlingresultsUIKitSwift5