본문 바로가기
Etc/Error

[Error] AttributeError: 'GradientBoostingClassifier' object has no attribute '_loss'

by VAMOSSS 2023. 1. 30.
반응형

AttributeError: 'GradientBoostingClassifier' object has no attribute '_loss'

Flask를 통해 Web 배포를 하는 도중 다음과 같은 오류가 발생했다.

 

2023-01-27 07:24:56,974: Exception on /predict [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2077, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1525, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1523, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1509, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/home/SizeRecSys/mysite/flask_app.py", line 200, in predict
    user_prediction_lst = finalSizeRecSys(userHeight, userWeight, userGender,
  File "/home/SizeRecSys/mysite/flask_app.py", line 81, in finalSizeRecSys
    + chongjang_model_soso.predict(userInfo) * c)
  File "/usr/local/lib/python3.10/site-packages/sklearn/ensemble/_gb.py", line 1881, in predict
    return self._raw_predict(X).ravel()
  File "/usr/local/lib/python3.10/site-packages/sklearn/ensemble/_gb.py", line 735, in _raw_predict
    raw_predictions = self._raw_predict_init(X)
  File "/usr/local/lib/python3.10/site-packages/sklearn/ensemble/_gb.py", line 728, in _raw_predict_init
    raw_predictions = self.loss_.get_init_raw_predictions(X, self.init_).astype(
AttributeError: 'GradientBoostingRegressor' object has no attribute 'loss_'

 

Web 배포는 무료 배포가 가능한 pythonAnywhere를 사용했다.

 

해당 오류는 모델을 학습시키고 저장한 로컬의 sklearn 버전과 웹 배포를 하는 환경의 sklearn 버전이 달라 발생했다.

 

모델을 학습하고 저장한 sklearn 버전과 웹 배포 환경의 sklearn 버전을 맞춰주니 바로 해결되었다.

내 환경에서는 모델을 학습한 로컬의 sklearn 버전이 1.1.2여서 pythonAnywhere의 sklearn 버전을 1.1.2로 설정하니 해결되었다.

$ pip install --user --upgrade scikit-learn==1.1.2

 

Reference

https://stackoverflow.com/questions/72396156/i-am-getting-this-error-in-my-flask-web-app-attributeerror-gradientboostingcl

https://www.pythonanywhere.com/forums/topic/30966/

반응형

댓글