使用DQN模型,代码绘制了在测试数据上获得的利润。x轴表示测试数据的指数,y轴表示DQN模型预测的相对利润增益。通过将训练利润相加并除以导入数据中的最后收盘价来计算相对收益。该图的标签为“rl (test)”。使用Matplotlib库的“show”函数...
Matplotlib的' plt '模块用于生成绘图。 plt.figure(figsize=(23,8)) plt.plot(data.index,((data['Close']-data['Close'][0])/data['Close'][-1]), label='buy and hold') plt.plot(train.index, ([0] + train_profits)/data['Close'][-1], label='rl (train)') plt.plot(test.index, ...
1.plot绘制线型图 plot是python中最基本的绘制二维线性折线图的函数 基本使用方式:plt.plot(x,y,s) 代码实现: import matplotlib.pyplot as plt import numpy as np import pandas as pd plt.rcParams['font.sans-serif'] = ['SimHei'] plt.rcParams['axes.unicode_minus'] = False #plt.plot(x,y,s)...
_frames, axis=-1) self._frames = None return self._out def __array__(self, dtype=None): out = self._force() if dtype is not None: out = out.astype(dtype) return out def __len__(self): return len(self._force()) def __getitem__(self, i): return self._force()[..., ...
model_selection import train_test_split %matplotlib inline # Treatment effect function def exp_te(x): return np.exp(2*x[0]) # DGP constants np.random.seed(123) n = 2000 n_w = 30 support_size = 5 n_x = 1 # Outcome support support_Y = np.random.choice(np.arange(n_w), size=...
这段代码定义了一个名为plot_train_test的函数,该函数使用Python绘图库Plotly创建可视化图。基于指定的日期,图表将股票数据分为训练集和测试集。输入参数包括train、test和date_split。 可视化结果如下: plot_train_test(train, test, date_split) 环境
(),dtype=np.int32)b_reward=np.array(batch[:, 2].tolist(),dtype=np.int32)b_obs=np.array(batch[:, 3].tolist(),dtype=np.float32).reshape(batch_size, -1)b_done=np.array(batch[:, 4].tolist(),dtype=np.bool)q=Q(b_pobs)maxq=np.max(Q_ast(b_obs).data,axis=1)target=...
具体到因果推断的例子上,我们只关心Treatment T 对 outcome Y的影响,因此我们可以首先使用X回归T,得到一个T的残差(实际T - 预测T),然后使用X回归Y,得到一个Y的残差(实际Y - 预测Y),最后使用T的残差回归Y的残差,估计的参数即我们想要的ATE。 (Y - (Y \sim X)) \sim (T - (T \sim X)) ...
importnumpyasnpimportmatplotlib.pyplotaspltfromsklearn.datasetsimportmake_moonsimporttorch# 使用GPU训练,可以在菜单 "代码执行工具" -> "更改运行时类型" 里进行设置device = torch.device("cuda:0"iftorch.cuda.is_available()else"cpu")# 这是一个展示数据的函数defplot_data(ax, X, Y, color ='bone'...
Applying the parallel axis theorem, we account for the rotational dynamics about the pendulum ends. The effects of any dissipative forces such as air resistance or friction are neglected therefore, the total mechanical energy is conserved. Mathematical formulation For this conservative system, the equat...