Exemple #1
0
 def get_hyper_preprocessors(self):
     hyper_preprocessors = []
     if self.column_names:
         hyper_preprocessors.append(
             hpps_module.DefaultHyperPreprocessor(
                 preprocessors.CategoricalToNumericalPreprocessor(
                     column_names=self.column_names,
                     column_types=self.column_types,
                 )))
     hyper_preprocessors.append(
         hpps_module.DefaultHyperPreprocessor(
             preprocessors.SlidingWindow(lookback=self.lookback,
                                         batch_size=self.batch_size)))
     return hyper_preprocessors
Exemple #2
0
def test_serialize_and_deserialize_default_hpps_categorical():
    x_train = np.array([["a", "ab", 2.1], ["b", "bc", 1.0], ["a", "bc",
                                                             "nan"]])
    preprocessor = preprocessors.CategoricalToNumericalPreprocessor(
        column_names=["column_a", "column_b", "column_c"],
        column_types={
            "column_a": "categorical",
            "column_b": "categorical",
            "column_c": "numerical",
        },
    )

    hyper_preprocessor = hyper_preprocessors.DefaultHyperPreprocessor(
        preprocessor)
    dataset = tf.data.Dataset.from_tensor_slices(x_train).batch(32)
    hyper_preprocessor.preprocessor.fit(
        tf.data.Dataset.from_tensor_slices(x_train).batch(32))
    hyper_preprocessor = hyper_preprocessors.deserialize(
        hyper_preprocessors.serialize(hyper_preprocessor))
    assert isinstance(
        hyper_preprocessor.preprocessor,
        preprocessors.CategoricalToNumericalPreprocessor,
    )

    result = hyper_preprocessor.preprocessor.transform(dataset)

    assert result[0][0] == result[2][0]
    assert result[0][0] != result[1][0]
    assert result[0][1] != result[1][1]
    assert result[0][1] != result[2][1]
    assert result[2][2] == 0
    assert result.dtype == tf.float32
Exemple #3
0
 def get_hyper_preprocessors(self):
     hyper_preprocessors = []
     if self._add_one_dimension:
         hyper_preprocessors.append(
             hpps_module.DefaultHyperPreprocessor(
                 preprocessors.AddOneDimension()))
     return hyper_preprocessors
Exemple #4
0
 def get_hyper_preprocessors(self):
     hyper_preprocessors = []
     hyper_preprocessors.append(
         hpps_module.DefaultHyperPreprocessor(
             preprocessors.SlidingWindow(lookback=self.lookback,
                                         batch_size=self.batch_size)))
     return hyper_preprocessors
def test_serialize_and_deserialize_default_hpps():
    preprocessor = preprocessors.AddOneDimension()
    hyper_preprocessor = hyper_preprocessors.DefaultHyperPreprocessor(preprocessor)
    hyper_preprocessor = hyper_preprocessors.deserialize(
        hyper_preprocessors.serialize(hyper_preprocessor)
    )
    assert isinstance(hyper_preprocessor.preprocessor, preprocessors.AddOneDimension)
Exemple #6
0
 def get_hyper_preprocessors(self):
     hyper_preprocessors = []
     if not self.has_channel_dim:
         hyper_preprocessors.append(
             hpps_module.DefaultHyperPreprocessor(
                 preprocessors.AddOneDimension()))
     return hyper_preprocessors
Exemple #7
0
 def get_hyper_preprocessors(self):
     hyper_preprocessors = []
     if self.dtype != tf.string:
         hyper_preprocessors.append(
             hpps_module.DefaultHyperPreprocessor(
                 preprocessors.CastToString()))
     return hyper_preprocessors
Exemple #8
0
    def get_hyper_preprocessors(self):
        hyper_preprocessors = []

        if self._add_one_dimension:
            hyper_preprocessors.append(
                hpps_module.DefaultHyperPreprocessor(
                    preprocessors.AddOneDimension()))

        if self.dtype in [tf.uint8, tf.uint16, tf.uint32, tf.uint64]:
            hyper_preprocessors.append(
                hpps_module.DefaultHyperPreprocessor(
                    preprocessors.CastToInt32()))

        if not self._encoded and self.dtype != tf.string:
            hyper_preprocessors.append(
                hpps_module.DefaultHyperPreprocessor(
                    preprocessors.CastToString()))

        if self._encoded_for_sigmoid:
            hyper_preprocessors.append(
                hpps_module.DefaultHyperPreprocessor(
                    preprocessors.SigmoidPostprocessor()))
        elif self._encoded_for_softmax:
            hyper_preprocessors.append(
                hpps_module.DefaultHyperPreprocessor(
                    preprocessors.SoftmaxPostprocessor()))
        elif self.num_classes == 2:
            hyper_preprocessors.append(
                hpps_module.DefaultHyperPreprocessor(
                    preprocessors.LabelEncoder(self._labels)))
        else:
            hyper_preprocessors.append(
                hpps_module.DefaultHyperPreprocessor(
                    preprocessors.OneHotEncoder(self._labels)))
        return hyper_preprocessors
Exemple #9
0
 def get_hyper_preprocessors(self):
     hyper_preprocessors = []
     if self._add_one_dimension:
         hyper_preprocessors.append(
             hpps_module.DefaultHyperPreprocessor(
                 preprocessors.AddOneDimension()))
     if self._dtype in [tf.uint8, tf.uint16, tf.uint32, tf.uint64]:
         hyper_preprocessors.append(
             hpps_module.DefaultHyperPreprocessor(
                 preprocessors.CastToInt32()))
     if not self._encoded and self._dtype != tf.string:
         hyper_preprocessors.append(
             hpps_module.DefaultHyperPreprocessor(
                 preprocessors.CastToString()))
     if self.multi_label:
         hyper_preprocessors.append(
             hpps_module.DefaultHyperPreprocessor(
                 preprocessors.MultiLabelEncoder()))
     if not self._encoded:
         if self.num_classes == 2 and not self.multi_label:
             hyper_preprocessors.append(
                 hpps_module.DefaultHyperPreprocessor(
                     preprocessors.LabelEncoder(self._labels)))
         else:
             hyper_preprocessors.append(
                 hpps_module.DefaultHyperPreprocessor(
                     preprocessors.OneHotEncoder(self._labels)))
     return hyper_preprocessors