我正在使用LSTM处理时间序列预测问题.输入包含多个功能,因此我使用的是多变量LSTM.问题是存在一些缺失值,例如:
Feature 1 Feature 2 ... Feature n
1 2 4 nan
2 5 8 10
3 8 8 5
4 nan 7 7
5 6 nan 12
Run Code Online (Sandbox Code Playgroud)
而不是插入缺失值,这可能会在结果中引入偏差,因为有时在同一个特征上有很多连续的时间戳和缺失值,我想知道是否有办法让LSTM学习缺失值,例如,使用掩蔽层或类似的东西?有人可以向我解释一下处理这个问题的最佳方法是什么?我正在使用Tensorflow和Keras.
simpson's rule从scipy.integrate库中使用时出现问题。即使所有数字均为正且x轴上的值从左向右递增,有时计算得出的面积也为负。例如:
from scipy.integrate import simps
x = [0.0, 99.0, 100.0, 299.0, 400.0, 600.0, 1700.0, 3299.0, 3300.0, 3399.0, 3400.0, 3599.0, 3699.0, 3900.0,
4000.0, 4300.0, 4400.0, 4900.0, 5000.0, 5100.0, 5300.0, 5500.0, 5700.0, 5900.0, 6100.0, 6300.0, 6600.0,
6900.0, 7200.0, 7600.0, 7799.0, 8000.0, 8400.0, 8900.0, 9400.0, 10000.0, 10600.0, 11300.0, 11699.0,
11700.0, 11799.0]
y = [3399.68, 3399.68, 3309.76, 3309.76, 3274.95, 3234.34, 3203.88, 3203.88, 3843.5,
3843.5, 4893.57, 4893.57, 4893.57, 4847.16, 4764.49, 4867.46, 4921.13, 4886.32,
4761.59, 4731.13, 4689.07, 4649.91, 4610.75, 4578.84, 4545.48, 4515.02, …Run Code Online (Sandbox Code Playgroud) 我有以下问题:我有一个这样的数据框:
col1 col2 col3
0 2 5 4
1 4 3 5
2 6 2 7
Run Code Online (Sandbox Code Playgroud)
现在我有一个数组,例如 a = [5,5,5] 并且我想在 col3 中插入这个数组,但只在特定的行(比如 0 和 2)中插入并获得类似的东西:
col1 col2 col3
0 2 5 [5,5,5]
1 4 3 5
2 6 2 [5,5,5]
Run Code Online (Sandbox Code Playgroud)
问题是,当我尝试这样做时:
zip_df.at[[0,2],'col3'] = a
Run Code Online (Sandbox Code Playgroud)
我收到以下错误ValueError: Must have equal len keys and value when setting with an ndarray。我怎么解决这个问题?
例如,我有一个 numpy 数组,假设它有一个形状 (10,10)。现在我想将 np.exp() 应用到这个数组,但只是一些满足条件的特定元素。例如,我想将 np.exp 应用于所有不是 0 或 1 的元素。有没有办法在不使用 for 循环遍历数组的每个元素的情况下做到这一点?
I would like to build a Neural Network that at the same time output a label for classification and a value for regression. I would like to do that using Keras. Right now my code is only for classification:
mdl = Sequential()
mdl.add(Dense(100, activation='relu', input_dim=X_train.shape[1]))
mdl.add(Dense(200, activation='relu'))
mdl.add(Dense(100, activation='relu'))
mdl.add(Dense(6, activation='softmax'))
mdl.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])
# early stopping implementation
filepath="weights.best.hdf5"
checkpoint = ModelCheckpoint(filepath, monitor='val_acc', verbose=1,
save_best_only=True, mode='max')
early_stop = EarlyStopping(monitor='val_acc', patience=100, mode='max')
callbacks_list = [checkpoint, early_stop]
# fit network
history = …Run Code Online (Sandbox Code Playgroud) python ×5
keras ×2
pandas ×2
arrays ×1
dataframe ×1
exp ×1
imputation ×1
integral ×1
lstm ×1
missing-data ×1
nan ×1
numpy ×1
scipy ×1
series ×1
tensorflow ×1