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

TypeError: 'NoneType' object is not iterable #1971

Closed
pseudotensor opened this issue Jan 27, 2019 · 14 comments · Fixed by #1973
Closed

TypeError: 'NoneType' object is not iterable #1971

pseudotensor opened this issue Jan 27, 2019 · 14 comments · Fixed by #1973

Comments

@pseudotensor
Copy link

fail.zip

Code was compiled for GPU. Uses hash: d169ac8

Issue has been there for many months, but we noticed it happening for non-trivial data as well so now posting issue with example.

@guolinke
Copy link
Collaborator

The root cause is the nan in evaluation score, and cause the wrong comparison result in early stopping.

@pseudotensor
Copy link
Author

So you don't have concerns about the data itself or the parameters? And the above fix should be good for these cases we see (many, especially for objectives other than plain regression) this score error -> NoneType issue?

@guolinke
Copy link
Collaborator

In gamma regression, the label should greater zero;
https://github.com/Microsoft/LightGBM/blob/52dbc5722fe0b80d224ee33ba5b064b80966e6c6/src/metric/regression_metric.hpp#L255
But in your code, there are many labels with zeros.
I think we should throw the error in these cases.

@pseudotensor
Copy link
Author

yes a direct error would be good

@pseudotensor
Copy link
Author

pseudotensor commented Jan 28, 2019

I think main issue here is that lightgbm thinks no trees are better than any amount of trees, and then the score becomes bad.

This is related to an issue before, when lightgbm would fail to generate at least an average (for regression) or most-common (for classification) target as the base model.

Yes, if negative labels (or <=0 for gamma), then agreed an error.

@pseudotensor
Copy link
Author

I'll try to find another case that isn't with a less common objective.

@pseudotensor
Copy link
Author

fail5.zip

Here's another case that fails in the same way. Yes, features are funny, but target is normal. Shouldn't fail. Should at least be able to recover average (for regression) or most frequent (for classification) model.

@guolinke
Copy link
Collaborator

guolinke commented Jan 28, 2019

@pseudotensor Actually, LightGBM have dummy trees for these cases.
I edit your pasted code for test that.

import _pickle as pickle
import pandas as pd
import numpy as np
import lightgbm as lgb
model = lgb.LGBMRegressor(bagging_seed=3137599, boosting_type='gbdt', class_weight=None,
                             colsample_bytree=0.8, 
                             feature_fraction_seed=3137598, gpu_device_id=1, gpu_platform_id=0,
                             importance_type='gain', learning_rate=0.05, max_bin=255,
                             max_delta_step=0, max_depth=-1, min_child_samples=1,
                             min_child_weight=1, min_data_in_bin=1, min_split_gain=0.0,
                             n_estimators=600, n_jobs=4, num_class=1, num_leaves=64,
                             objective='regression', random_state=None, reg_alpha=0.0,
                             reg_lambda=1.0, scale_pos_weight=1, silent=True, subsample=1.0,
                             subsample_for_bin=200000, subsample_freq=1, verbose=2)
X, y, sample_weight, init_score, eval_set, valid_X_features, eval_sample_weight, init_score, eval_metric, early_stopping_rounds, X_features, verbose_fit = pickle.load(open("data.pkl", "rb"))
y = y/y.max()
valid_y = eval_set[0][1]
# below uncommented has no issues
#valid_y = valid_y/valid_y.max()
eval_set[0] = (eval_set[0][0], valid_y)
model.fit(X, y)
p = model.predict(eval_set[0][0])

and the values of p is

array([0.33332364, 0.33332364, 0.33332364, ..., 0.33332364, 0.33332364,
       0.33332364])

The fail reason is the same as above case, due to the l2 loss is inf (too large range of test label).

@pseudotensor
Copy link
Author

Ok, I think as long as the error is improved, this can be closed.

@pseudotensor
Copy link
Author

Here is a corner case that could be fixed too:

fail6.zip

Basically all sample weights for the eval set are 0. But even if the eval set can't be used for some reason, should at least be able to predict the average (dummy trees) model.

@guolinke
Copy link
Collaborator

@pseudotensor
It actually has the dummy trees. tested by your code

model.fit(X, y, sample_weight=sample_weight, init_score=init_score, eval_set=eval_set, eval_init_score=init_score, eval_metric=eval_metric, eval_sample_weight=eval_sample_weight)
model.predict(X)
model.predict(eval_set[0][0])

As well as the early_stopping_rounds is removed, the model can provide the average prediction.

@pseudotensor
Copy link
Author

Understood, but even if there is a bad eval_set or early stopping, the worse case should be dummy trees always. It shouldn't have failed even with early stopping turned on.

@guolinke
Copy link
Collaborator

@pseudotensor yeah, the fixes are in #1973
and your cases are added as test cases 😄

@pseudotensor
Copy link
Author

Awesome, thanks!

guolinke added a commit that referenced this issue Jan 30, 2019
* always save the score of the first round in early stopping

fix #1971

* avoid using std::log on non-positive numbers

* remove unnecessary changes

* add tests

* Update test_sklearn.py

* enhanced tests
alisterw pushed a commit to G-Research/LightGBM that referenced this issue Feb 13, 2019
#2)

* [ci] removed temp brew hotfix and deprecated sudo option (microsoft#1951)

* removed brew hotfix and deprecated sudo option on Travis

* removed brew hotfix on Azure

* updated Boost docs (microsoft#1955)

* removed warnings about types in comparison ([-Wsign-compare]) (microsoft#1953)

* removed comparison warning

* fixed spacing

* [docs] ask to provide LightGBM version for issue (microsoft#1958)

* [R] Fix multiclass demo (microsoft#1940)

* Fix multiclass custom objective demo

* Use option not to boost from average instead of setting init score explicitly

* Reference microsoft#1846 when turning off boost_from_average

* Add trailing whitespace

* [R] Correcting lgb.prepare output comment (microsoft#1831)

* Correcting lgb.prepare output comment

* updated Roxygen files

* [docs] bump xcode version in docs (microsoft#1952)

* fix typo

* [docs] Added the links to the libraries used (microsoft#1962)

* Added links to the libraries used.

* Fixing the header

* Fixes

* ot -> to

* [docs] fixed minor typos in documentation (microsoft#1959)

* fixed minor typos in documentation

* fixed typo in gpu_tree_learner.cpp

* Update .gitignore

* support to override some parameters in Dataset (microsoft#1876)

* add warnings for override parameters of Dataset

* fix pep8

* add feature_penalty

* refactor

* add R's code

* Update basic.py

* Update basic.py

* fix parameter bug

* Update lgb.Dataset.R

* fix a bug

* Fix build on macOS Mojave (microsoft#1923)

* Fix build on macOS Mojave

Fixed microsoft#1898

- https://iscinumpy.gitlab.io/post/omp-on-high-sierra/
- https://cliutils.gitlab.io/modern-cmake/chapters/packages/OpenMP.html
- Homebrew/homebrew-core#20589

* update setup.py

* update docs

* fix setup.py

* update docs

* update docs

* update setup.py

* update docs

* [tests][python] added tests for metrics' behavior and fixed case for multiclass task with custom objective (microsoft#1954)

* added metrics test for standard interface

* simplified code

* less trees

* less trees

* use dummy custom objective and metric

* added tests for multiclass metrics aliases

* fixed bug in case of custom obj and num_class > 1

* added metric test for sklearn wrapper

* [python][R][docs] added possibility to install with Visual Studio 2019 Preview (microsoft#1956)

* Found error from microsoft#1939 (microsoft#1974)

* fix more edge cases in mape (microsoft#1977)

* fix R's overflow (microsoft#1960)

* [tests][python] added test for huge string model (microsoft#1964)

* added test for huge string model

* fixed tree sizes field

* simplified model structure

* fixed test and added try/except

* fix nan in eval results (microsoft#1973)

* always save the score of the first round in early stopping

fix microsoft#1971

* avoid using std::log on non-positive numbers

* remove unnecessary changes

* add tests

* Update test_sklearn.py

* enhanced tests

* fix microsoft#1981

* [python] added OpenMP options for python-package installation (microsoft#1975)

* added OpenMP options for python-package installation

* fixed grammar typo

* improved model loading routines (microsoft#1979)

* [ci] refined command status check  (microsoft#1980)

* refined command status check

* refined Appveyor

* redirect all warnings to stdout

* cpplint whitespaces and new lines (microsoft#1986)

* fix microsoft#1994

* [docs] Fixed OpenCL Debian package name typo (microsoft#1995)

[docs] Fixed OpenCL Debian package name typo

* [python] convert datatable to numpy directly (microsoft#1970)

* convert datatable to numpy directly

* fix according to comments

* updated more docstrings

* simplified isinstance check

* Update compat.py

* [R-package] Fix demos not using lgb.Dataset.create.valid (microsoft#1993)

* Hand edit broken commit

* Hand edit broken commit

* Hand edit broken commit

* Hand edit broken commit

* 2.2.3 release (microsoft#1987)

* Update DESCRIPTION

* Update DESCRIPTION

* update version number at master branch (microsoft#1996)

* Update VERSION.txt

* Update .appveyor.yml

* Update DESCRIPTION

* Initial attempt to implement appending features in-memory to another data set

The intent is for this to enable munging files together easily, without needing to round-trip via numpy or write multiple copies to disk.
In turn, that enables working more efficiently with data sets that were written separately.

* Implement Dataset.dump_text, and fix small bug in appending of group bin boundaries.

Dumping to text enables us to compare results, without having to worry about issues like features being reordered.

* Add basic tests for validation logic for add_features_from.

* Remove various internal mapping items from dataset text dumps

These are too sensitive to the exact feature order chosen, which is not visible to the user.
Including them in tests appears unnecessary, as the data dumping code should provide enough coverage.

* Add test that add_features_from results in identical data sets according to dump_text.

* Add test that booster behaviour after using add_features_from matches that of training on the full data

This checks:
- That training after add_features_from works at all
- That add_features_from does not cause training to misbehave

* Expose feature_penalty and monotone_types/constraints via get_field

These getters allow us to check that add_features_from does the right thing with these vectors.

* Add tests that add_features correctly handles feature_penalty and monotone_constraints.

* Ensure add_features_from properly frees the added dataset and add unit test for this

Since add_features_from moves the feature group pointers from the added dataset to the dataset being added to, the added dataset is invalid after the call.
We must ensure we do not try and access this handle.

* Remove some obsolete TODOs

* Tidy up DumpTextFile by using a single iterator for each feature

This iterators were also passed around as raw pointers without being freed, which is now fixed.

* Factor out offsetting logic in AddFeaturesFrom

* Remove obsolete TODO

* Remove another TODO

This one is debatable, test code can be a bit messy and duplicate-heavy, factoring it out tends to end badly.
Leaving this for now, will revisit if adding more tests later on becomes a mess.

* Add documentation for newly-added methods.

* Initial work towards add_data_from

This currently only merges the feature groups and updates num_data_.
It does not deal with Metadata or non-dense bins yet.

* Fix bug where dense bin copy of num_data_ wasn't updated

* Small bug fix in dense_bin.hpp, initial implementation of Merge for 4-bits bin.

* Add unit test for dense bin case of add_data_from, and refactor tests slightly.

* Initial implementation of Merge for sparse bins and unit tests for it.

* Ensure we test merging sparse data sets after loading them from binary

This seems silly, but push_buffers_ aren't populated if the data was loaded from a binary file.
This forces us to reconstruct the index,value form of the data in the target bin before merging.
Adding this test ensures that code is covered.

* Add labels to text dumps.

* Add weights to text dumps.

* Ensure add_data_from properly merges labels.

* Ensure metadata appends weights correctly, and unit test for it.

* Implement metadata merging for query bits

This is currently not covered by unit tests.

* Check datasets are aligned before merging.

This catches the majority of obvious errors, e.g. not having the same number of features or having different bin mappings.

* Add test that booster behaviour is preserved by add_data_from.

* Add configuration parameters for CEGB.

* Add skeleton CEGB tree learner

Like the original CEGB version, this inherits from SerialTreeLearner.
Currently, it changes nothing from the original.

* Track features used in CEGB tree learner.

* Pull CEGB tradeoff and coupled feature penalty from config.

* Implement finding best splits for CEGB

This is heavily based on the serial version, but just adds using the coupled penalties.

* Set proper defaults for cegb parameters.

* Ensure sanity checks don't switch off CEGB.

* Implement per-data-point feature penalties in CEGB.

* Implement split penalty and remove unused parameters.

* Merge changes from CEGB tree learner into serial tree learner

* Represent features_used_in_data by a bitset, to reduce the memory overhead of CEGB, and add sanity checks for the lengths of the penalty vectors.
@lock lock bot locked as resolved and limited conversation to collaborators Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants