What's the best way to test whether an sklearn model has been fitted?

后端 未结 4 995
误落风尘
误落风尘 2021-02-07 02:30

What\'s the most elegant way to check whether an sklearn model has been fitted? i.e. whether its fit() function has been called after it was instantiated, or not. <

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-07 03:05

    I do this for classifiers:

    def check_fitted(clf): 
        return hasattr(clf, "classes_")
    

提交回复
热议问题