-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Using XGBClassifier.Predict after load_model causes 'XGBClassifier' object has no attribute '_le' #2073
Comments
Environment info Operating System: linux based on docker Package used (python/R/jvm/C++): python xgboost version used: 0.6 If you are using python package, please provide The python version and distribution: version - 2.7.5 Steps to reproduce
y_pred = clf.predict(X_test) This happens because _le attribute is set in fit function: so what's the solution, basically, if we call load_model, there is no need to call fit, and according to the former post, that's the cause.... |
Maybe check if self._le is instantiated in both fit and predict. If not, then create it. |
oh, but how to instantiate the parameter inside xgboost predefined function.. I think the problem is because we use XGBClassifier which is sklearn API in the first place. but save_model and dump_model and load_model is actually xgboost's native function.. they are not compatible, and in fact we don't have the corresponding model saving model inside sklearn...... so some use Pickle etc. the third party packages |
I had to use a workaround.
But assigning _le can be done inside predict function. And it would help avoiding misleading exceptions. |
but what if we don't have y_test, the normal scene when we do real test....? |
Can expected classed be extracted from the booster? |
@mangolzy If you don't have the y_test, you just need the classes:
|
For bugs or installation issues, please provide the following information.
The more information you provide, the more easily we will be able to offer
help and advice.
Environment info
Operating System: Windows 10
Compiler: Unofficial windows binaries
Package used (python/R/jvm/C++): python
xgboost
version used: 0.6If you are using python package, please provide
xgboost
if you are not installing from source: python setup.py installSteps to reproduce
y_pred = clf.predict(X_test)
3.
AttributeError: 'XGBClassifier' object has no attribute '_le'
in "predict" function on line 485:
return self._le.inverse_transform(column_indexes)
This happens because _le attribute is set in fit function:
self._le = XGBLabelEncoder().fit(y)
If you don't call fit, _le is not set, so exception is reaised.
The text was updated successfully, but these errors were encountered: