示例#1
0
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)
示例#2
0
 def build(self, hp, inputs=None):
     input_node = nest.flatten(inputs)[0]
     output_node = input_node
     output_node = preprocessor.LightGBMRegressor()(output_node)
     output_node = block.IdentityBlock()(output_node)
     output_node = head.EmptyHead(loss='mean_squared_error',
                                  metrics=[self.metrics])(output_node)
     return output_node
示例#3
0
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])
    input_node = ak.Input()
    output_node = input_node
    output_node = preprocessor.LightGBMRegressor()(output_node)
    output_node = block.IdentityBlock()(output_node)
    output_node = head.EmptyHead(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)
    auto_model.tuner.get_best_models()[0].summary()
    assert result.shape == (11, 1)
示例#4
0
def lightgbm_head(lightgbm_block):
    lightgbm_block.heads = fetch_heads(lightgbm_block)
    if len(lightgbm_block.heads) > 1:
        raise ValueError('LightGBMBlock can only be connected to one head.')
    head = lightgbm_block.heads[0]
    if isinstance(head, head_module.ClassificationHead):
        classifier = preprocessor_module.LightGBMClassifier(seed=lightgbm_block.seed)
        classifier.num_classes = head.num_classes
        lightgbm_block.lightgbm_block = classifier
    if isinstance(head, head_module.RegressionHead):
        lightgbm_block.lightgbm_block = preprocessor_module.LightGBMRegressor(
            seed=lightgbm_block.seed)

    in_block = head
    # Check if the head has no other input but only LightGBMBlock.
    while in_block is not lightgbm_block:
        # The head has other inputs.
        if len(in_block.inputs) > 1:
            return
        in_block = in_block.inputs[0].in_blocks[0]
    head.identity = True