Пример #1
0
class TestFeature(AsyncTestCase):
    def setUp(self):
        self.feature = Feature()

    def test_default_dtype(self):
        self.assertEqual(self.feature.dtype(), int)

    def test_default_length(self):
        self.assertEqual(self.feature.length(), 1)

    async def test_default_applicable(self):
        self.assertEqual(await self.feature.applicable(Data("test")), True)

    def test_load_def(self):
        feature = Feature.load_def("test", "float", 10)
        self.assertEqual(feature.NAME, "test")
        self.assertEqual(feature.dtype(), float)
        self.assertEqual(feature.length(), 10)

    def test_convert_dtype(self):
        self.assertEqual(Feature.convert_dtype("float"), float)

    def test_convert_dtype_invalid(self):
        with self.assertRaisesRegex(TypeError, "Failed to convert"):
            Feature.convert_dtype("not a python data type")
Пример #2
0
class TestFeature(AsyncTestCase):
    def setUp(self):
        self.feature = Feature()

    def test_default_dtype(self):
        self.assertEqual(self.feature.dtype(), int)

    def test_default_length(self):
        self.assertEqual(self.feature.length(), 1)

    async def test_default_applicable(self):
        self.assertEqual(await self.feature.applicable(Data('test')), True)
Пример #3
0
 def feature_feature_column(self, feature: Feature):
     '''
     Creates a feature column for a feature
     '''
     dtype = feature.dtype()
     if not inspect.isclass(dtype):
         LOGGER.warning('Unknown dtype %r. Cound not create column' % (dtype))
         return None
     if dtype is int or issubclass(dtype, int) \
             or dtype is float or issubclass(dtype, float):
         return self._tf.feature_column.numeric_column(feature.NAME,
                 shape=feature.length())
     LOGGER.warning('Unknown dtype %r. Cound not create column' % (dtype))
     return None
Пример #4
0
 def _feature_feature_column(self, feature: Feature):
     """
     Creates a feature column for a feature
     """
     dtype = feature.dtype()
     if not inspect.isclass(dtype):
         self.logger.warning("Unknown dtype %r. Cound not create column" %
                             (dtype))
         return None
     if (dtype is int or issubclass(dtype, int) or dtype is float
             or issubclass(dtype, float)):
         return tensorflow.feature_column.numeric_column(
             feature.NAME, shape=feature.length())
     self.logger.warning("Unknown dtype %r. Cound not create column" %
                         (dtype))
     return None