name 'LGBMRegressor' is not defined
anindya5 opened this issue · comments
I am getting this error while trying to use the MimicExplainer in your advanced-feature-transformations-explain-local.ipynb notebook.
I have lightgbm and all installed, but cannot seem to get this working. The SHAP based explainers are working fine, but running
explainer = MimicExplainer(clf.steps[-1][1],
x_train,
LGBMExplainableModel,
augment_data=True,
max_num_of_augmentations=10,
features=x_train.columns,
transformations=transformations,
allow_all_transformations=True)
gives the error
NameError Traceback (most recent call last)
<ipython-input-27-abf3dd406d1c> in async-def-wrapper()
27
28
---> 29
30
31
~/anaconda3/envs/interp/lib/python3.6/site-packages/interpret_community/dataset/decorator.py in init_wrapper(self, model, initialization_examples, *args, **kwargs)
36 if not isinstance(initialization_examples, DatasetWrapper):
37 initialization_examples = DatasetWrapper(initialization_examples)
---> 38 return init_func(self, model, initialization_examples, *args, **kwargs)
39 return init_wrapper
~/anaconda3/envs/interp/lib/python3.6/site-packages/interpret_community/mimic/mimic_explainer.py in __init__(self, model, initialization_examples, explainable_model, explainable_model_args, is_function, augment_data, max_num_of_augmentations, explain_subset, features, classes, transformations, allow_all_transformations, shap_values_output, categorical_features, model_task, reset_index, **kwargs)
302 explainable_model_args[ExplainParams.SHAP_VALUES_OUTPUT] = shap_values_output
303 self.surrogate_model = _model_distill(self.function, explainable_model, training_data,
--> 304 original_training_data, explainable_model_args)
305 self._method = self.surrogate_model._method
306 self._original_eval_examples = None
~/anaconda3/envs/interp/lib/python3.6/site-packages/interpret_community/mimic/model_distill.py in _model_distill(teacher_model_predict_fn, uninitialized_surrogate_model, data, original_training_data, explainable_model_args)
67 **explainable_model_args)
68 else:
---> 69 surrogate_model = uninitialized_surrogate_model(**explainable_model_args)
70 if is_classifier and teacher_y.shape[1] == 2:
71 # Make sure output has only 1 dimension
~/anaconda3/envs/interp/lib/python3.6/site-packages/interpret_community/mimic/models/lightgbm_model.py in __init__(self, multiclass, random_state, shap_values_output, classification, **kwargs)
93 initializer = LGBMClassifier
94 else:
---> 95 initializer = LGBMRegressor
96 self._lgbm = initializer(random_state=random_state, **initializer_args)
97 super(LGBMExplainableModel, self).__init__(**kwargs)
NameError: name 'LGBMRegressor' is not defined
Hi @anindya5 --
This appears to be a question that's better suited for the interpret-community repo. Transferring it there so they can help you.
-InterpretML
@anindya5 strange, can you do the import manually in your python environment?
from lightgbm import LGBMRegressor, LGBMClassifier, Booster
init_func = LGBMRegressor
Perhaps the import errors are getting suppressed here, do you see anything printed:
with warnings.catch_warnings():
warnings.filterwarnings('ignore', 'Starting from version 2.2.1', UserWarning)
import shap
try:
from lightgbm import LGBMRegressor, LGBMClassifier, Booster
import lightgbm
if (version.parse(lightgbm.__version__) <= version.parse('2.2.1')):
print("Using older than supported version of lightgbm, please upgrade to version greater than 2.2.1")
except ImportError:
print("Could not import lightgbm, required if using LGBMExplainableModel")
@anindya5 is this issue resolved? Are you able to proceed?
Regards
@anindya5, closing this issue since there is no response on this thread. Please feel free to reopen if you continue to run into this error.
Regards
Still seeing this issue ? Does anyone has any resolution ?
@nayanaramakanth Sorry about the issue you are having. Do you have lightgbm package installed in your environment? Can you show the output of:
pip show lightgbm
Specifically what version of lightgbm you have?
Hi,
I'm having the same problem. In my case I'm following this AzureML tutorial.
https://docs.microsoft.com/en-us/azure/machine-learning/how-to-machine-learning-interpretability
And when I try to execute this part:
from interpret.ext.blackbox import MimicExplainer
from lightgbm import LGBMRegressor, LGBMClassifier, Booster
init_func = LGBMRegressor
# you can use one of the following four interpretable models as a global surrogate to the black box model
from interpret.ext.glassbox import LGBMExplainableModel
from interpret.ext.glassbox import LinearExplainableModel
from interpret.ext.glassbox import SGDExplainableModel
from interpret.ext.glassbox import DecisionTreeExplainableModel
# "features" and "classes" fields are optional
# augment_data is optional and if true, oversamples the initialization examples to improve surrogate model accuracy to fit original model. Useful for high-dimensional data where the number of rows is less than the number of columns.
# max_num_of_augmentations is optional and defines max number of times we can increase the input data size.
# LGBMExplainableModel can be replaced with LinearExplainableModel, SGDExplainableModel, or DecisionTreeExplainableModel
explainer2 = MimicExplainer(model,
x_train,
LGBMExplainableModel,
augment_data=True,
max_num_of_augmentations=10,
features=breast_cancer_data.feature_names,
classes=classes)_
I have the commented error
C:\ProgramData\Anaconda3\lib\site-packages\interpret_community\mimic\models\lightgbm_model.py in __init__(self, multiclass, random_state, shap_values_output, classification, **kwargs)
173 initializer = LGBMClassifier
174 else:
--> 175 initializer = LGBMRegressor
176 self._lgbm = initializer(random_state=random_state, **initializer_args)
177 super(LGBMExplainableModel, self).__init__(**kwargs)
NameError: name 'LGBMRegressor' is not defined_
Here is the result of "pip show lightgbm"
Name: lightgbm
Version: 3.3.2
Summary: LightGBM Python Package
Home-page: https://github.com/microsoft/LightGBM
Author: None
Author-email: None
License: The MIT License (Microsoft)
Location: c:\programdata\anaconda3\lib\site-packages
Requires: numpy, scipy, wheel, scikit-learn
Required-by:
Thanks in advance for your support
Hi @nayanaramakanth can you help with this, thanks in advance....
@rnavarromatesanz
can you try doing an import in your python environment manually, eg:
from lightgbm import LGBMRegressor, LGBMClassifier, Booster
this error indicates that this import is just not working for some reason