He implementado un modelo de regresión con keras para predecir valores comprendidos entre e-06 y e-16. Como resultado obtengo todas las predicciones en torno a e-07.
def _base_model():
model = Sequential()
model.add(Dense(20, kernel_regularizer='l2', input_dim=12, activation='relu'))
model.add(BatchNormalization())
model.add(Dense(20, kernel_regularizer='l2', activation='relu'))
model.add(BatchNormalization())
model.add(Dense(1, kernel_regularizer='l2', activation='sigmoid'))
optimizer = Adam(lr=0.0004)
model.compile(loss='mean_squared_error', optimizer=optimizer)
return model
mms_x = MinMaxScaler()
mms_y = MinMaxScaler()
x_n = mms_x.fit_transform(x)
y_n = mms_y.fit_transform(np.reshape(y, (-1, 1)))
x_test_n = mms_x.transform(x_test)
y_test_n = mms_y.transform(np.reshape(y_test, (-1, 1)))
estimator = KerasRegressor(build_fn=_base_model, batch_size=int(0.5 * x_n.shape[0]), epochs=500, verbose=0)
estimator.fit(x_n, y_n)
prediction = estimator.predict(x_test_n)
y_prediction = mms_y.inverse_transform(np.reshape(prediction, (-1, 1)))
A continuación, adjunto una muestra de los resultados de los datos usados para testear. Dónde y_test son los valores reales, y_test_n son los valores reales normalizados, x_test son los valores de entrada, x_test_n son los valores de entrada normalizados, prediction son los valores predichos y y_prediction son los valores predichos por la red neuronal desnormalizados.
x_test =array([[ 9.13032945e-01, 4.48543615e-01, 1.21471379e-01, 4.59691231e-01, -7.04107682e-03, 5.73655959e-01, 1.00000000e+01, 1.68139129e+02, 1.69052954e+00, 2.35857913e+03, 1.89170054e-01, 3.43569995e+05],
[ 7.37279859e-01, -5.96543058e-01, 6.84791770e-02, 4.41210980e-01, -4.92003347e-01, 4.64064726e-01, 1.20000000e+01, 1.68480774e+02, 1.15835211e+00, 2.38161126e+03, 2.34036465e-01, 3.72224318e+05],
[-2.59021404e-01, 3.71261309e-01, -2.16156287e-01, 5.43236826e-01, -5.49188926e-01, 4.30326427e-01, 1.10000000e+01, 1.60467909e+02, 2.15319911e+00, 2.25034828e+03, 1.02604495e-01, 3.50939780e+05],
[-1.48442354e-01, -2.42855924e-01, 1.45341381e+00, 1.61903722e-01, -4.49263401e-01, -4.97033700e-02, 1.00000000e+01, 1.63156903e+02, 1.04367354e+00, 2.29026170e+03, 3.45005454e-03, 3.67569205e+05],
[ 3.10436067e-01, 6.74157574e-01, -6.90708038e-01, 4.13188254e-01, -2.11920676e-01, -2.27031896e-02, 9.00000000e+00, 1.58041848e+02, 2.95811262e+00, 2.34772870e+03, 2.06509396e-03, 3.91810272e+05]])
x_test_n = array([[ 0.94321214, 0.64423385, 0.36997323, 0.4599793, 0.93059294, 0.71810821, 0.6 , 0.87906269, 0.3443942 , 0.94814897, 0.75761119, 0.03479036],
[ 0.82539998, 0.17762936, 0.35188916, 0.4412975 , 0.60524863, 0.64474332, 1. , 0.90215806, 0.07711882, 0.97723242, 0.94246606, 0.3247232 ],
[ 0.15755166, 0.60972927, 0.25475472, 0.54443608, 0.56688481, 0.62215752, 0.8 , 0.36048499, 0.57676067, 0.81148219, 0.40095094, 0.10936 ],
[ 0.23167586, 0.33554163, 0.82451071, 0.158944 , 0.63392137, 0.3008058 , 0.6 , 0.54226209, 0.01952382, 0.86188222,-0.00757698, 0.27762139]
[ 0.53927477, 0.74496471, 0.09280962, 0.41296914, 0.79314635, 0.31888084, 0.4 , 0.19648227, 0.98101225, 0.93444776, -0.01328318, 0.52289961]])
y_test = array([[2.27514056e-08],
[2.91341941e-14],
[4.97753140e-14],
[5.77807211e-12],
[1.77576774e-14]])
y_test_n = array([[3.35294144e-03],
[4.29323122e-09],
[7.33517368e-09],
[8.51531092e-07],
[2.61664056e-09]])
prediction = array([[0.13964666],
[0.09875984],
[0.0484926 ],
[0.14387827],
[0.04030625]])
y_prediction = array([[9.4757331e-07],
[6.7013553e-07],
[3.2904686e-07],
[9.7628686e-07],
[2.7349833e-07]])
Se utilizan 85 datos para entrenar la red neuronal.