神经网络回归预测所有测试样本的相同值

我的 神经网络回归模型可以预测所有测试样本的一个值。. 玩超参数,如epochs、batch_size、层数、隐藏单元、学习率等,只是将预测值改变为一个新的常数。

测试方面,如果我在训练数据本身进行测试,我得到的结果几乎是准确的,RMSE~1。

注:任务是根据机器运行到失效的时间序列数据来预测机器的剩余寿命。我使用tsfresh库从原始时间序列数据中生成1045个特征,只有24个特征。

应该是什么原因导致这种行为?我应该如何可视化神经网络模型的开发,以确保事情的发展方向是正确的?

print "Shape of training_features is", train_X.shape
print "Shape of train_labels is", train_Y.shape
print "Shape of test_features is", test_X.shape
print "shape of test_labels is", test_Y.shape

input_dim = train_X.shape[1]
# Function to create model, required for KerasRegressor
def create_model(h1=50, h2=50, act1='sigmoid', act2='sigmoid', init='he_normal', learn_rate=0.001, momentum=0.1, loss='mean_squared_error'):
    # create model
    model = Sequential()
    model.add(Dense(h1, input_dim=input_dim, init=init, activation=act1))
    model.add(Dense(h2, init=init, activation=act2))
    model.add(Dense(1, init=init))
    # Compile model
    optimizer = SGD(lr=learn_rate, momentum=momentum)
    model.compile(loss=loss, optimizer=optimizer, metrics=['accuracy'])
    return model

''' THE REAL THING '''
# create model
model = KerasRegressor(build_fn=create_model, verbose=0)

# SCORING FUNCTION
grid_scorer = make_scorer(mean_squared_error, greater_is_better=False)
# Grid Search
batch_size = [8]
epochs = [500]
init_mode = ['glorot_uniform']
learn_rate = [0.0001]
momentum = [0.1]

hidden_layer_1 = [75]
activation_1 = ['sigmoid']
hidden_layer_2 = [15]
activation_2 = ['sigmoid']

param_grid = dict(batch_size=batch_size, nb_epoch=epochs, init=init_mode, h1=hidden_layer_1, h2=hidden_layer_2, act1 = activation_1, act2=activation_2, learn_rate=learn_rate, momentum=momentum)

print "\n...BEGIN SEARCH..."
grid = GridSearchCV(estimator=model, param_grid=param_grid, cv=5, scoring=grid_scorer, verbose=1)

print "\nLet's fit the training data..."
grid_result = grid.fit(train_X, train_Y)

# summarize results
print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_))
means = grid_result.cv_results_['mean_test_score']
stds = grid_result.cv_results_['std_test_score']
params = grid_result.cv_results_['params']
for mean, stdev, param in zip(means, stds, params):
    print("%f (%f) with: %r" % (mean, stdev, param))

predicted = grid.predict(test_X)  
print "\nPrediction array is\n", predicted
rmse = numpy.sqrt(((predicted - test_Y) ** 2).mean(axis=0))
print "Test RMSE is", rmse

输出。

Shape of training_features is (249, 1045)
Shape of train_labels is (249,)
Shape of test_features is (248, 1045)
shape of test_labels is (248,)

...BEGIN SEARCH...

Let's fit the training data...
Fitting 5 folds for each of 1 candidates, totalling 5 fits
Best: -891.761863 using {'learn_rate': 0.0001, 'h2': 15, 'act1': 'sigmoid', 'act2': 'sigmoid', 'h1': 75, 'batch_size': 8, 'init': 'glorot_uniform', 'nb_epoch': 500, 'momentum': 0.1}
-891.761863 (347.253351) with: {'learn_rate': 0.0001, 'h2': 15, 'act1': 'sigmoid', 'act2': 'sigmoid', 'h1': 75, 'batch_size': 8, 'init': 'glorot_uniform', 'nb_epoch': 500, 'momentum': 0.1}

Prediction array is
[ 295.72067261  295.72067261  295.72067261  295.72067261  295.72067261
  295.72067261  295.72067261  ...
                              295.72067261  295.72067261  295.72067261
  295.72067261  295.72067261  295.72067261]
Test RMSE is 95.0019297411

解决方案:

你应该尝试缩放你的数据。 这种情况通常发生在特征没有被缩放的时候。

给TA打赏
共{{data.count}}人
人已打赏
解决方案

无法读取 axios 包装器的 undefined 属性 'then' 。

2022-5-13 15:00:17

解决方案

如何用acos-cos-radians公式选择不同的一列,但返回所有列。

2022-5-13 15:00:19

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索