microsoft / microsoft/qlib

error of function finetune of class LGBModel

Open
#1,064 1 comment 0 reactions 1 assignee View on GitHub

@SunsetWolf is already working on this.

Since May 6, 2022.

bug
Dominant language
Python
Stars
48.7k
Forks
7.7k
PR merge metrics
No merged PRs in 30d

Description

🐛 Bug Description

Using function of finetune of class LGBModel raised AttributeError: 'tuple' object has no attribute 'empty'.

To Reproduce

Steps to reproduce the behavior:

  1. Training LGBModel and saving params to 'LGB_params.pkl'.
  2. Init model from 'LGB_params.pkl'.
  3. Using function finetune.

Expected Behavior

Screenshot

Environment

Note: User could run cd scripts && python collect_info.py all under project directory to get system information
and paste them here directly.

  • Qlib version: 0.8.4
  • Python version: 3.7
  • OS (Windows, Linux, MacOS): Windows
  • Commit number (optional, please provide it if you are using the dev version):

Additional Notes

I read the raw code, the error located at line 111 of file : anaconda3\Lib\site-packages\qlib\contrib\model\gbdt.py.
Here is the raw code:

    def finetune(self, dataset: DatasetH, num_boost_round=10, verbose_eval=20, reweighter=None):
        """
        finetune model

        Parameters
        ----------
        dataset : DatasetH
            dataset for finetuning
        num_boost_round : int
            number of round to finetune model
        verbose_eval : int
            verbose level
        """
        # Based on existing model and finetune by train more rounds
        dtrain, _ = self._prepare_data(dataset, reweighter)  # pylint: disable=W0632
        if dtrain.empty:
            raise ValueError("Empty data from dataset, please check your dataset config.")
        self.model = lgb.train(
            self.params,
            dtrain,
            num_boost_round=num_boost_round,
            init_model=self.model,
            valid_sets=[dtrain],
            valid_names=["train"],
            verbose_eval=verbose_eval,
        )

dtrain is a tuple and function _prepare_data has already checked whether the dataset is empty, so I think the code could be modified to:

    def finetune(self, dataset: DatasetH, num_boost_round=10, verbose_eval=20, reweighter=None):
        """
        finetune model

        Parameters
        ----------
        dataset : DatasetH
            dataset for finetuning
        num_boost_round : int
            number of round to finetune model
        verbose_eval : int
            verbose level
        """
        # Based on existing model and finetune by train more rounds
        dtrain, _ = self._prepare_data(dataset, reweighter)  # pylint: disable=W0632
        self.model = lgb.train(
            self.params,
            dtrain[0],
            num_boost_round=num_boost_round,
            init_model=self.model,
            valid_sets=[dtrain[0]],
            valid_names=["train"],
            verbose_eval=verbose_eval,
        )

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.