我尝试参加我的第一次 Kaggle 比赛,其中RMSLE
给出了所需的损失函数。因为我没有找到如何实现这个loss function
我试图解决的问题RMSE
。我知道这是Keras
过去的一部分,有没有办法在最新版本中使用它,也许通过自定义功能backend
?
这是我设计的NN:
from keras.models import Sequential
from keras.layers.core import Dense , Dropout
from keras import regularizers
model = Sequential()
model.add(Dense(units = 128, kernel_initializer = "uniform", activation = "relu", input_dim = 28,activity_regularizer = regularizers.l2(0.01)))
model.add(Dropout(rate = 0.2))
model.add(Dense(units = 128, kernel_initializer = "uniform", activation = "relu"))
model.add(Dropout(rate = 0.2))
model.add(Dense(units = 1, kernel_initializer = "uniform", activation = "relu"))
model.compile(optimizer = "rmsprop", loss = "root_mean_squared_error")#, metrics =["accuracy"])
model.fit(train_set, label_log, batch_size = 32, epochs = 50, validation_split = 0.15)
我尝试了root_mean_squared_error
在 GitHub 上找到的自定义函数,但据我所知,语法不是必需的。我认为y_true
and they_pred
必须在传递给 return 之前定义,但我不知道到底是怎么回事,我刚开始用 python 编程,我的数学真的不是那么好......
from keras import backend as K
def root_mean_squared_error(y_true, y_pred):
return K.sqrt(K.mean(K.square(y_pred - y_true), axis=-1))
我收到此功能的以下错误:
ValueError: ('Unknown loss function', ':root_mean_squared_error')
感谢您的想法,感谢您的每一个帮助!