2

我有以下功能可以将输入/输出标准化/反转为值列表。现在我想将它反向应用到张量,这样我就可以用“真实”单位写出损失值。显然,这不能直接应用于张量。当然这可以通过手动计算来完成,但我想知道是否有框架方法可以做到这一点?我发现tf.nn.l2_normalize但不确定这是我需要的,以及如何反转它。

def _transform(self, x_in, y_in):
    print(x_in, y_in)
    if not hasattr(self, "x_scaler"):
        self.x_scaler = preprocessing.StandardScaler().fit(_sample_feature_matrix(x_in))
        self.y_scaler = preprocessing.StandardScaler().fit(_sample_feature_matrix(y_in))
    x_std = self.x_scaler.transform(_sample_feature_matrix(x_in))
    y_std = self.y_scaler.transform(_sample_feature_matrix(y_in))
    return x_std, y_std

def _inverse_y(self, y_std):
   return self.y_scaler.inverse_transform(_sample_feature_matrix(y_std)) 

"""Converts a list of samples with a single feature value in each to  n_samples, n_features) matrix suitable for sklearn"""
def _sample_feature_matrix(in_list):
    return np.array(in_list).reshape(-1, 1)
4

0 回答 0