我正在为基因表达数据构建一个自动编码器。有些基因不表达,输入中含有NaN。我的输出(预测)都是NaN。这是我的损失函数:
def nan_mse(y_actual, y_predicted):
per_instance = tf.where(tf.is_nan(y_actual),
tf.zeros_like(y_actual),
tf.square(tf.subtract(y_predicted, y_actual)))
return tf.reduce_mean(per_instance, axis=0)
和型号:
input_data = Input(shape=(1,num_genes))
#Leaky-Parametric-RelU
#Encoder
x = Dense(num_genes)(input_data)
encoder = PReLU()(x)
#Battleneck layer
encoded = Dense(64, activation = 'sigmoid')(encoder)
#Decoder
x = Dense(num_genes)(encoded)
decoder = PReLU()(x)
autoencoder = Model(input_data, decoder)
autoencoder.compile(loss=nan_mse, optimizer = 'adam')
autoencoder.summary()
history = autoencoder.fit(x_train,x_train, epochs =50, verbose = 2),
callbacks = [MyCustomCallback()])
我的目标是让网络忽略NaN值,但重要的是在输入中预先输入它们。这可以通过完成损失函数来实现吗
现在输出是NaN。此处有用户建议编辑代码,以便:
def nan_mse(y_actual, y_predicted):
stack = tf.stack((tf.is_nan(y_actual),
tf.is_nan(y_predicted)),
axis=1)
is_nans = tf.keras.backend.any(stack, axis=1)
per_instance = tf.where(is_nans,
tf.zeros_like(y_actual),
tf.square(tf.subtract(y_predicted, y_actual)))
print(per_instance)
return tf.reduce_mean(per_instance, axis=0)
现在我的损失是0.0000e+00,但这并不能解决根本问题
x=pd.read\u csv(“C:/Users/10.csv”,index\u col=False).groupby(['Column\u name\u optional']).mean().reset\u index()
x=x.replace(np.nan,0)
这将用零替换所有NaN
相关问题 更多 >
编程相关推荐