def transform(self, data):
        """Return imputed data by trained TGAIN model.
    
    Args:
      - data: incomplete 3d numpy array
      
    Returns:
      - data_imputed: complete 3d numpy array after imputation
    """
        # Only after fitting
        assert self.gain_model is not None

        # Data preprocessing
        no, time, dim = data.shape
        data_concat = np.reshape(data, [no * time, dim])
        # Only with non-padded data
        idx = np.where(data_concat[:, 1] != -1)[0]

        # Apply TGAIN
        data_imputed = data_concat.copy()
        data_imputed[idx, :] = self.gain_model.transform(data_concat[idx, :])

        # Rounding
        data_imputed = rounding(data_concat, data_imputed)

        # Return to 3d array
        data_imputed = np.reshape(data_imputed, [no, time, dim])

        return data_imputed
Beispiel #2
0
    def transform(self, data):
        """Return imputed data by trained GAIN model.
        
        Args:
            - data: 2d numpy array with missing data
            
        Returns:
            - imputed data: 2d numpy array without missing data
        """
        # Only after fitting
        assert self.norm_parameters is not None
        assert os.path.exists(self.save_file_directory) is True

        min_val = self.norm_parameters["min"]
        max_val = self.norm_parameters["max"]

        no, dim = data.shape
        # Set missing
        m = 1 - (1 * (np.isnan(data)))
        x = np.nan_to_num(data)

        ## Imputed data
        z = self.sample_Z(no, dim)
        x = m * x + (1 - m) * z

        # Restore the trained GAIN model
        graph = tf.Graph()
        with graph.as_default():
            with tf.Session() as sess:
                tf.saved_model.loader.load(sess, [tag_constants.SERVING],
                                           self.save_file_directory)
                X = graph.get_tensor_by_name("Placeholder_2:0")
                M = graph.get_tensor_by_name("Placeholder:0")
                G_sample = graph.get_tensor_by_name("Sigmoid:0")

                imputed_data = sess.run(G_sample, feed_dict={X: x, M: m})

        # Renormalize
        for i in range(dim):
            imputed_data[:, i] = imputed_data[:, i] * (max_val[i] + 1e-8)
            imputed_data[:, i] = imputed_data[:, i] + min_val[i]

        # Rounding
        imputed_data = rounding(x, imputed_data)

        return imputed_data
Beispiel #3
0
    def transform(self, dataset):
        """Return imputed dataset by standard imputation.
    
    Args:
      - dataset: incomplete dataset
    
    Returns:
      - dataset: imputed dataset by standard imputation.
    """
        assert self.imputation_model is not None

        if dataset.static_feature is not None:
            # Standard imputation
            data_imputed = self.imputation_model.transform(
                dataset.static_feature)
            # Rounding
            dataset.static_feature = rounding(dataset.static_feature,
                                              data_imputed)

        return dataset
 def transform (self, data):
   """Return imputed data by trained MRNN model.
   
   Args:
     - data: 3d numpy array with missing data
     
   Returns:
     - data_imputed: 3d numpy array with imputed data
   """
   # Only after fit
   assert self.median_vals is not None
   assert self.mrnn_model is not None
   # Data preprocess for mrnn
   x, m, t, data_new, _ = self.mrnn_data_preprocess(data)
   
   # Impute missing data
   imputed_x = self.mrnn_model.transform(x, m, t, self.median_vals)    
   data_imputed = (1-m) * imputed_x + m * data_new
   
   # Rounding
   data_imputed = rounding(data_new, data_imputed)
   
   return data_imputed