def test_lgbm_classifier(tmp_dir): x_train = np.random.rand(11, 32) y_train = np.array([[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]]) input_node = ak.Input() output_node = input_node output_node = preprocessor.LightGBMBlock()(output_node) output_node = head.ClassificationHead(loss='categorical_crossentropy', metrics=['accuracy'])(output_node) auto_model = ak.GraphAutoModel(input_node, output_node, directory=tmp_dir, max_trials=1) auto_model.fit(x_train, y_train, epochs=1, validation_data=(x_train, y_train)) result = auto_model.predict(x_train) assert result.shape == (11, 10)
def test_lgbm_regressor(): dataset = common.generate_data(11, (32, ), dtype='dataset') y = common.generate_data(11, (1, ), dtype='dataset') instance = preprocessor_module.LightGBMBlock(seed=common.SEED) instance.lightgbm_block = preprocessor_module.LightGBMRegressor( seed=common.SEED) new_dataset = run_preprocessor(instance, dataset, y, tf.float32) assert isinstance(new_dataset, tf.data.Dataset)
def test_lgbm_classifier(): dataset = common.generate_data(11, (32,), dtype='dataset') y = common.generate_one_hot_labels(11, dtype='dataset') instance = preprocessor.LightGBMBlock(seed=common.SEED) instance.lightgbm_block = preprocessor.LightGBMClassifier(seed=common.SEED) new_dataset = run_preprocessor(instance, dataset, y, tf.float32) assert isinstance(new_dataset, tf.data.Dataset)
def test_lgbm_classifier(): dataset = common.generate_data(100, (32, ), dtype='dataset') y = common.generate_one_hot_labels(100, num_classes=3, dtype='dataset') instance = preprocessor_module.LightGBMBlock(seed=common.SEED) instance.lightgbm_block = preprocessor_module.LightGBMClassifier( seed=common.SEED) instance.lightgbm_block.num_classes = 3 new_dataset = run_preprocessor(instance, dataset, y, tf.float32) for (x, ) in new_dataset: assert x.shape == (3, ) break assert isinstance(new_dataset, tf.data.Dataset)
def test_lgbm_classifier_two_classes(): dataset = common.generate_data(11, (32, ), dtype='dataset') y = tf.data.Dataset.from_tensor_slices( np.random.randint(0, 2, 11).reshape(-1, 1)) instance = preprocessor_module.LightGBMBlock(seed=common.SEED) instance.lightgbm_block = preprocessor_module.LightGBMClassifier( seed=common.SEED) instance.lightgbm_block.num_classes = 11 new_dataset = run_preprocessor(instance, dataset, y, tf.float32) for (x, ) in new_dataset: assert x.shape == (1, ) break assert isinstance(new_dataset, tf.data.Dataset)
def build_body(self, hp, input_node): if len(self.heads) > 1: module_type_choices = ['dense'] else: module_type_choices = ['lightgbm', 'dense'] module_type = self.module_type or hp.Choice( 'module_type', module_type_choices, default=module_type_choices[0]) if module_type == 'dense': output_node = block.DenseBlock()(input_node) elif module_type == 'lightgbm': output_node = preprocessor.LightGBMBlock( seed=self.seed)(input_node) else: raise ValueError( 'Unsupported module' 'type: {module_type}'.format(module_type=module_type)) nest.flatten(output_node)[0].shape = self.output_shape return output_node
def test_lgbm_regressor(tmp_dir): x_train = np.random.rand(11, 32) y_train = np.array([1.1, 2.1, 4.2, 0.3, 2.4, 8.5, 7.3, 8.4, 9.4, 4.3]) y_train = y_train.reshape(-1, 1) input_node = ak.Input() output_node = input_node output_node = preprocessor.LightGBMBlock()(output_node) output_node = head.RegressionHead(loss='mean_squared_error', metrics=['mean_squared_error' ])(output_node) auto_model = ak.GraphAutoModel(input_node, output_node, directory=tmp_dir, max_trials=1) auto_model.fit(x_train, y_train, epochs=1, validation_data=(x_train, y_train)) result = auto_model.predict(x_train) assert result.shape == (11, 1)