
182
|
第
5
章
该策略似乎比训练数据集上的基础工具(样本内,没有交易成本)的表现要好一些。
但是,更有趣的问题是它如何在测试数据集(样本外)上执行。开始不稳定
,
但是
之后该策略的表现也超出了基本工具的样本外性能,如图
5-21
所示。尽管事实是分
类器的准确性仅在测试数据集上略高于
50%
:
In [172]: model.evaluate(test_data_[cols], test_data['direction'])
16/16 [==============================] - 0s 676us/step - loss: 0.7292 -
accuracy: 0.5050
Out[172]: [0.7292129993438721, 0.5049701929092407]
In [173]: pred = np.where(model.predict(test_data_[cols]) > 0.5, 1, 0)
In [174]: test_data['prediction'] = np.where(pred > 0, 1, -1)
In [175]: test_data['prediction'].value_counts()
Out[175]: -1 368
1 135
Name: prediction, dtype: int64
In [176]: test_data['strategy'] = (test_data['prediction'] ...