我在Keras中定义了一个自定义函数来计算R平方度量。我在keras后端使用了以下代码:
import keras.backend as K
def Rsqured(y_true,y_pred):
y_true = K.batch_flatten(y_true)
y_pred = K.batch_flatten(y_pred)
y_tr_mean = K.mean(y_true)
y_pr_mean = K.mean(y_pred)
num = K.sum((y_true-y_tr_mean) * (y_pred-y_pr_mean))
num = num^2
denom = K.sum((y_true-y_tr_mean)*(y_true-y_tr_mean)) * K.sum((y_pred-
y_pr_mean)*(y_pred-y_pr_mean))
return num
/德诺
后来,当我把它称为我的模型时:
model.compile(optimizer='adam',loss='mean_squared_error', metrics=[Rsqured])
我得到以下错误:
Input 'x' of 'LogicalOr' Op has type int64 that does not match expected type of bool.
问题就在这里:
num = num^2
^
是按位异或运算符。你想要**
相关问题 更多 >
编程相关推荐