Fix #3894: Allow loading pickles without self.booster attributes (#3938)

The addition of self.booster attribute broke backward compatibility.
This commit is contained in:
Philip Hyunsu Cho 2018-11-23 12:15:50 -08:00 committed by GitHub
parent 7d3149a21f
commit f9302a56fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -518,7 +518,7 @@ class XGBModel(XGBModelBase):
feature_importances_ : array of shape ``[n_features]``
"""
if self.booster != 'gbtree':
if getattr(self, 'booster', None) is not None and self.booster != 'gbtree':
raise AttributeError('Feature importance is not defined for Booster type {}'
.format(self.booster))
b = self.get_booster()
@ -542,7 +542,7 @@ class XGBModel(XGBModelBase):
-------
coef_ : array of shape ``[n_features]`` or ``[n_classes, n_features]``
"""
if self.booster != 'gblinear':
if getattr(self, 'booster', None) is not None and self.booster != 'gblinear':
raise AttributeError('Coefficients are not defined for Booster type {}'
.format(self.booster))
b = self.get_booster()
@ -571,7 +571,7 @@ class XGBModel(XGBModelBase):
-------
intercept_ : array of shape ``(1,)`` or ``[n_classes]``
"""
if self.booster != 'gblinear':
if getattr(self, 'booster', None) is not None and self.booster != 'gblinear':
raise AttributeError('Intercept (bias) is not defined for Booster type {}'
.format(self.booster))
b = self.get_booster()