Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dask] TypeError: Unknown type of parameter:init_score, got:Series #4409

Closed
darshanbint opened this issue Jun 26, 2021 · 5 comments
Closed
Labels

Comments

@darshanbint
Copy link

Description

Reproducible example

Environment info

LightGBM version or commit hash:

Command(s) you used to install LightGBM

Additional Comments

@StrikerRUS
Copy link
Collaborator

Try to pass init_score as an argument not as part of params.
Please provide reproducible example, otherwise we cannot help you.

@darshanbint
Copy link
Author

darshanbint commented Jun 27, 2021

Error log:

Finding random open ports for workers
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-19-4463b2b3ec8a> in <module>
----> 1 model.fit(df2[feature_list], df2[target_list])

~/miniconda3/envs/darshanbint/lib/python3.9/site-packages/lightgbm/dask.py in fit(self, X, y, sample_weight, init_score, **kwargs)
    728     ) -> "DaskLGBMClassifier":
    729         """Docstring is inherited from the lightgbm.LGBMClassifier.fit."""
--> 730         return self._lgb_dask_fit(
    731             model_factory=LGBMClassifier,
    732             X=X,

~/miniconda3/envs/darshanbint/lib/python3.9/site-packages/lightgbm/dask.py in _lgb_dask_fit(self, model_factory, X, y, sample_weight, init_score, group, **kwargs)
    615         params.pop("client", None)
    616 
--> 617         model = _train(
    618             client=_get_dask_client(self.client),
    619             data=X,

~/miniconda3/envs/darshanbint/lib/python3.9/site-packages/lightgbm/dask.py in _train(client, data, label, params, model_factory, sample_weight, init_score, group, **kwargs)
    448     ]
    449 
--> 450     results = client.gather(futures_classifiers)
    451     results = [v for v in results if v]
    452     model = results[0]

~/miniconda3/envs/darshanbint/lib/python3.9/site-packages/distributed/client.py in gather(self, futures, errors, direct, asynchronous)
   1980             else:
   1981                 local_worker = None
-> 1982             return self.sync(
   1983                 self._gather,
   1984                 futures,

~/miniconda3/envs/darshanbint/lib/python3.9/site-packages/distributed/client.py in sync(self, func, asynchronous, callback_timeout, *args, **kwargs)
    851             return future
    852         else:
--> 853             return sync(
    854                 self.loop, func, *args, callback_timeout=callback_timeout, **kwargs
    855             )

~/miniconda3/envs/darshanbint/lib/python3.9/site-packages/distributed/utils.py in sync(loop, func, callback_timeout, *args, **kwargs)
    352     if error[0]:
    353         typ, exc, tb = error[0]
--> 354         raise exc.with_traceback(tb)
    355     else:
    356         return result[0]

~/miniconda3/envs/darshanbint/lib/python3.9/site-packages/distributed/utils.py in f()
    335             if callback_timeout is not None:
    336                 future = asyncio.wait_for(future, callback_timeout)
--> 337             result[0] = yield future
    338         except Exception as exc:
    339             error[0] = sys.exc_info()

~/miniconda3/envs/darshanbint/lib/python3.9/site-packages/tornado/gen.py in run(self)
    760 
    761                     try:
--> 762                         value = future.result()
    763                     except Exception:
    764                         exc_info = sys.exc_info()

~/miniconda3/envs/darshanbint/lib/python3.9/site-packages/distributed/client.py in _gather(self, futures, errors, direct, local_worker)
   1845                             exc = CancelledError(key)
   1846                         else:
-> 1847                             raise exception.with_traceback(traceback)
   1848                         raise exc
   1849                     if errors == "skip":

~/miniconda3/envs/darshanbint/lib/python3.9/site-packages/lightgbm/dask.py in _train_part()
    116             model.fit(data, label, sample_weight=weight, init_score=init_score, group=group, **kwargs)
    117         else:
--> 118             model.fit(data, label, sample_weight=weight, init_score=init_score, **kwargs)
    119 
    120     finally:

~/miniconda3/envs/darshanbint/lib/python3.9/site-packages/lightgbm/sklearn.py in fit()
    888                     valid_sets[i] = (valid_x, self._le.transform(valid_y))
    889 
--> 890         super().fit(X, _y, sample_weight=sample_weight, init_score=init_score, eval_set=valid_sets,
    891                     eval_names=eval_names, eval_sample_weight=eval_sample_weight,
    892                     eval_class_weight=eval_class_weight, eval_init_score=eval_init_score,

~/miniconda3/envs/darshanbint/lib/python3.9/site-packages/lightgbm/sklearn.py in fit()
    681             init_model = init_model.booster_
    682 
--> 683         self._Booster = train(params, train_set,
    684                               self.n_estimators, valid_sets=valid_sets, valid_names=eval_names,
    685                               early_stopping_rounds=early_stopping_rounds,

~/miniconda3/envs/darshanbint/lib/python3.9/site-packages/lightgbm/engine.py in train()
    226     # construct booster
    227     try:
--> 228         booster = Booster(params=params, train_set=train_set)
    229         if is_valid_contain_train:
    230             booster.set_train_data_name(train_data_name)

~/miniconda3/envs/darshanbint/lib/python3.9/site-packages/lightgbm/basic.py in __init__()
   2227                 )
   2228             # construct booster object
-> 2229             train_set.construct()
   2230             # copy the parameters from train_set
   2231             params.update(train_set.get_params())

~/miniconda3/envs/darshanbint/lib/python3.9/site-packages/lightgbm/basic.py in construct()
   1466             else:
   1467                 # create train
-> 1468                 self._lazy_init(self.data, label=self.label,
   1469                                 weight=self.weight, group=self.group,
   1470                                 init_score=self.init_score, predictor=self._predictor,

~/miniconda3/envs/darshanbint/lib/python3.9/site-packages/lightgbm/basic.py in _lazy_init()
   1247                 params['categorical_column'] = sorted(categorical_indices)
   1248 
-> 1249         params_str = param_dict_to_str(params)
   1250         self.params = params
   1251         # process for reference dataset

~/miniconda3/envs/darshanbint/lib/python3.9/site-packages/lightgbm/basic.py in param_dict_to_str()
    234             pairs.append(str(key) + '=' + str(val))
    235         elif val is not None:
--> 236             raise TypeError('Unknown type of parameter:%s, got:%s'
    237                             % (key, type(val).__name__))
    238     return ' '.join(pairs)

TypeError: Unknown type of parameter:init_score, got:Series

code

init_score = some_float_value * np.log(df[some_column] / (int(1) - df[some_column])) 
# type(df): <class 'dask.dataframe.core.DataFrame'>
# type(init_score): <class 'dask.dataframe.core.Series'> 

# failed on:
model =  lgb.DaskLGBMClassifier(**TRAINING_PARAMETERS, client=client, init_score=init_score)

model.fit(df[feature_list], df[target_list])

@jameslamb
Copy link
Collaborator

Thanks very much for including a bit more information. I've reformatted #4409 (comment) a bit for better readability. Please see https://docs.github.com/en/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax if you are new to GitHub and not familiar with GitHub-flavored markdown used in posts here.


I can see from your code that you are passing init_score to the constructor of lgb.DaskLGBMClassifier. This is not supported. Please try passing init_score into DaskLGBMClassifier.fit() instead.

Please consult the documentation, which shows where to pass these values:


If that works for you, please comment here so the issue can be closed.

If the error persists, please provide a fully reproducible example. That should be code that can be run without modification which reproduces the error. If you are not experienced in this, please see the definition at https://stackoverflow.com/help/minimal-reproducible-example for some guidance.

Your reproducible example should also include answers to these questions which were asked in the issue template when you opened this issue:

  • LightGBM version or commit hash:
  • Command(s) you used to install LightGBM

@jameslamb jameslamb changed the title TypeError: Unknown type of parameter:init_score, got:Series, how do deal this? [dask] TypeError: Unknown type of parameter:init_score, got:Series Jun 28, 2021
@darshanbint
Copy link
Author

Worked fine, thanks!

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants