So, i have time series, and want to predict the same time series one step ahead. Unfortunately, a lot of the data is missing. I want to use sample weights, so that is a field is missing, it is not added to the loss. However, sample_weights can be 1D (by default), or 2D (when sample_weight_mode is set to temporal). However, I want them to be 3D - e.g. my input is (100, 1000, 100), and my output is (100, 1000, 5) - (samples, timesteps, features). When I use 2D weights, if a row in my output has only one missing value, the whole row's information is discarded.
What I want to do is something like this:
sample_weights = (1-np.isnan(X))
model = Model(input = inputs, output = dense)
model.compile(optimizer="rmsprop", loss="mae", sample_weight_mode="temporal")
model.fit(X, y, sample_weight=sample_weights )
But I get an exception:
Using Theano backend.
Traceback (most recent call last):
File "test.py", line 21, in <module>
model.fit(values[:,:-1,:], values[:,1:,:], sample_weight=sample_weights )
File "/home/hristo/mlenv/local/lib/python2.7/site-packages/keras/engine/training.py", line 1032, in fit
batch_size=batch_size)
File "/home/hristo/mlenv/local/lib/python2.7/site-packages/keras/engine/training.py", line 970, in _standardize_user_data
in zip(y, sample_weights, class_weights, self.sample_weight_modes)]
File "/home/hristo/mlenv/local/lib/python2.7/site-packages/keras/engine/training.py", line 367, in standardize_weights
str(sample_weight.shape) + '. '
Exception: Found a sample_weight array with shape (214, 36, 1305). In order to use timestep-wise sample weighting, you should pass a 2D sample_weight array.