我有来自Keras网的以下输出:
batch_cut_train = training_set_size - Y_train.shape[0]
batch_cut_test = abs(training_set_size - Y.shape[0]) - Y_test.shape[0]
first_output = model.predict(X_test, batch_size=batch_size)
output = pd.DataFrame(first_output, index=features[-Y_test.shape[0]-batch_cut_test:-batch_cut_test].index, columns=labels.columns)
当我的数据完全被batch_size整除时,我得到batch_cut_train = 0.然后,当我将其索引到要素中时,我得到了
features[:-0]
会抛出错误。什么是避免这种情况的干净方法?
错误为ValueError: Shape of passed values is (6, 1696), indices imply (6, 0)
,因为它索引为0,因此功能(pd.DataFrame)中显示的范围基本上是空的。
编辑:这解决了它,但可能不是最好的方法:
batch_cut_train = training_set_size - Y_train.shape[0]
batch_cut_test = abs(training_set_size - Y.shape[0]) - Y_test.shape[0]
first_output = model.predict(X_test, batch_size=batch_size)
if batch_cut_test != 0:
output = pd.DataFrame(first_output, index=features[-Y_test.shape[0]-batch_cut_test:-batch_cut_test].index, columns=labels.columns)
else:
output = pd.DataFrame(first_output, index=features[-Y_test.shape[0]:].index, columns=labels.columns)
o = output.join(df['PX LAST'])
o.tail()