【发布时间】:2019-12-03 22:32:46
【问题描述】:
我正在使用引导技术来评估 MLPClassifier,并且我正在使用 scikit.utils.resample 来获取不同的随机样本,但 x_test 和 y_test 返回的是空的:
seeds = [50,51,52,53,54]
for i in range(5): # number of bootstrap samples
X_train, y_train = resample(X, y, n_samples=len(X), random_state=seeds[i], stratify=y)
X_test = [x for x in X if x not in X_train] # test = samples that weren't selected for train
y_test = [y for y in y if y not in y_train] # test = samples that weren't selected for train
X_test
# []
我做错了什么? /有没有更好的方法来做到这一点?很难相信sklearn 没有提供更好的方法。
【问题讨论】:
-
你的初始
X和y是列表还是 numpy 数组? -
X和y是 numpy 数组 -
回答没有帮助?
-
我会测试,我可能出错了,因为
y_test是空的。 -
在下面的回答中做了一些细微的更正 -
y_test不需要转换为列表,它应该按原样工作(前提是它确实是一个 1D numpy 数组)。
标签: python arrays numpy scikit-learn resampling