Ejemplo n.º 1
0
 def test_nmf_with_all_datasets(self):
     should_succeed = ['digits']
     should_fail = ['irisArr', 'irisDf', 'housing', 'creditG', 'movies', 'drugRev']
     for name in should_succeed:
         dataset = getattr(self, f'_{name}')
         NMF.validate_schema(**dataset)
     for name in should_fail:
         dataset = getattr(self, f'_{name}')
         with self.assertRaises(ValueError):
             NMF.validate_schema(**dataset)
Ejemplo n.º 2
0
 def test_nmf_with_all_datasets(self):
     should_succeed = ["digits"]
     should_fail = ["irisArr", "irisDf", "housing", "creditG", "movies", "drugRev"]
     for name in should_succeed:
         dataset = getattr(self, f"_{name}")
         NMF.validate_schema(**dataset)
     for name in should_fail:
         dataset = getattr(self, f"_{name}")
         with self.assertRaises(ValueError):
             NMF.validate_schema(**dataset)
Ejemplo n.º 3
0
 def test_init_fit_predict(self):
     import lale.datasets
     nmf = NMF()
     lr = LogisticRegression()
     trainable = nmf >> lr
     (train_X, train_y), (test_X, test_y) = lale.datasets.digits_df()
     trained = trainable.fit(train_X, train_y)
     predicted = trained.predict(test_X)
Ejemplo n.º 4
0
 def test_init_fit_transform(self):
     import lale.datasets
     from lale.lib.lale import Both
     nmf = NMF()
     pca = PCA()
     trainable = Both(op1=nmf, op2=pca)
     (train_X, train_y), (test_X, test_y) = lale.datasets.digits_df()
     trained = trainable.fit(train_X, train_y)
     transformed = trained.transform(test_X)
Ejemplo n.º 5
0
 def test_input_schema_fit(self):
     self.maxDiff = None
     self.assertEqual(
         LogisticRegression.input_schema_fit(),
         LogisticRegression.get_schema("input_fit"),
     )
     self.assertEqual(
         (NMF >> LogisticRegression).input_schema_fit(), NMF.get_schema("input_fit")
     )
     self.assertEqual(
         IdentityWrapper(op=LogisticRegression).input_schema_fit(),
         LogisticRegression.get_schema("input_fit"),
     )
     actual = (TfidfVectorizer | NMF).input_schema_fit()
     expected = {
         "anyOf": [
             {
                 "type": "object",
                 "required": ["X"],
                 "additionalProperties": False,
                 "properties": {
                     "X": {
                         "anyOf": [
                             {"type": "array", "items": {"type": "string"}},
                             {
                                 "type": "array",
                                 "items": {
                                     "type": "array",
                                     "minItems": 1,
                                     "maxItems": 1,
                                     "items": {"type": "string"},
                                 },
                             },
                         ]
                     },
                     "y": {},
                 },
             },
             {
                 "type": "object",
                 "required": ["X"],
                 "additionalProperties": False,
                 "properties": {
                     "X": {
                         "type": "array",
                         "items": {
                             "type": "array",
                             "items": {"type": "number", "minimum": 0.0},
                         },
                     },
                     "y": {},
                 },
             },
         ]
     }
     self.assertEqual(actual, expected)
Ejemplo n.º 6
0
 def test_input_schema_fit(self):
     self.maxDiff = None
     self.assertEqual(LogisticRegression.input_schema_fit(),
                      LogisticRegression.get_schema('input_fit'))
     self.assertEqual((NMF >> LogisticRegression).input_schema_fit(),
                      NMF.get_schema('input_fit'))
     self.assertEqual(
         IdentityWrapper(op=LogisticRegression).input_schema_fit(),
         LogisticRegression.get_schema('input_fit'))
     actual = (TfidfVectorizer | NMF).input_schema_fit()
     expected = {
         'anyOf': [{
             'type': 'object',
             'required': ['X'],
             'additionalProperties': False,
             'properties': {
                 'X': {
                     'anyOf': [{
                         'type': 'array',
                         'items': {
                             'type': 'string'
                         }
                     }, {
                         'type': 'array',
                         'items': {
                             'type': 'array',
                             'minItems': 1,
                             'maxItems': 1,
                             'items': {
                                 'type': 'string'
                             }
                         }
                     }]
                 },
                 'y': {}
             }
         }, {
             'type': 'object',
             'required': ['X'],
             'additionalProperties': False,
             'properties': {
                 'X': {
                     'type': 'array',
                     'items': {
                         'type': 'array',
                         'items': {
                             'type': 'number',
                             'minimum': 0.0
                         }
                     }
                 },
                 'y': {}
             }
         }]
     }
     self.assertEqual(actual, expected)
Ejemplo n.º 7
0
 def test_not_randome_state(self):
     with EnableSchemaValidation():
         with self.assertRaises(jsonschema.ValidationError):
             _ = NMF(random_state='"not RandomState"')