I have tested several kinds of regressors from scikit-learn. But, when I use if-statement only with regressor, I faced the error case like the sample code below.
from sklearn.neural_network import MLPRegressor
from sklearn.ensemble import GradientBoostingRegressor, HistGradientBoostingRegressor
for j, model in enumerate([MLPRegressor(), HistGradientBoostingRegressor(), GradientBoostingRegressor()]):
if model:
print(f'{j}: True. You defined the model: %s'%type(model))
0: True. You defined the model: <class 'sklearn.neural_network._multilayer_perceptron.MLPRegressor'>
1: True. You defined the model: <class 'sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingRegressor'>
AttributeError: 'GradientBoostingRegressor' object has no attribute 'estimators_'
Unlike the first two models, only the third model causes AttributeError. On the other hand, if model is not None: doesn't cause the error.
Why is that?