Lightgbm: [Python] AttributeError: 'Booster' object has no attribute 'network'

Created on 2 Dec 2017  路  9Comments  路  Source: microsoft/LightGBM

Environment info

Operating System: Windows Server 2012 R2 Standard
CPU: Intel Xeon CPU X5650 @ 2.67GHZ
C++/Python/R version: Python 3.6, pip installed LightGBM 2.0.11

Error Message:

Exception ignored in: <bound method Booster.__del__ of <lightgbm.basic.Booster object at 0x0000004A00609BE0>>
Traceback <most recent call last>:
  File "C:\Continuum\Anaconda3\lib\site-package\lightgbm\basic.py", line 1351, in __del__
    if self.network:
AttributeError: 'Booster' object has no attribute 'network'

The code seems running through but throws this exception at the very end. There is no traceback to the code so not sure where it gets wrong. There is no exception when running the code on other Windows PC (Windows 7).

The code is only using LightGBM for prediction with a model read from a Pickle file:

def predict(model, data):
    pred_prob = pd.Series(model.predict_proba(data)[:, 1], name='pred_prob')
    pred = pd.Series(model.predict(data), name='pred')
    LOGGER.info("Prediction Success")
    LOGGER.info("{:d} True Out Of {:d} Total ({:.2f}%)".format(
        int(pred.sum()), len(pred), pred.sum()/len(pred)*100))
    return pred_prob, pred

And later use Lime to plot an Explainer:

def ......
            cat_features = [x_cols.index(i) for i in cat_cols]
            predict_fn = lambda x: model.predict_proba(x).astype(float)
            explainer = lime.lime_tabular.LimeTabularExplainer(
                np.array(data),
                feature_names=x_cols,
                class_names=['False', 'True'],
                categorical_features=cat_features,
                categorical_names=cat_cols)
            neg_samples = np.random.choice(np.reshape(np.asarray(np.where(
                pred_prob < 0.2)), -1), 5, False)
            pos_samples = np.random.choice(np.reshape(np.asarray(np.where(
                pred_prob > 0.8)), -1), 5, False)

Please help to figure out where causes this exception.

Thank you!

All 9 comments

@wxchan

I think It's caused by __del__. Some similar issue: https://stackoverflow.com/questions/16620932/tracing-an-ignored-exception-in-python. I am not sure how to fix it yet. Maybe add a try/except in __del__? @StrikerRUS are you familiar with this?

@wxchan I just know that bahavior of __del__ often is weird :-(

I suppose it's not critical task and could be wrapped into try/except as you suggested.

@hangyao I submit a pr (#1095 ) to fix this, can you try whether it works?

@wxchan This PR fixes the issue. Thank you very much for your prompt solution!

ah thanks for the pr! just chiming in here -- we'd love to use quantile regression feature here in 2.0.11 but we're seeing this issue which is blocking us from migrating up. When this pr gets merged, do you think you all could cut a release for a 2.0.12? thank you!

just curious, @guolinke -- when do you think we'll see another release?

@elaser the release is created about monthly

ah k ty!

Was this page helpful?
0 / 5 - 0 ratings