1. 程式人生 > >sklearn 通過檢查是否具有屬性確定是否擬合過了

sklearn 通過檢查是否具有屬性確定是否擬合過了

As model_selection.GridSearchCV uses set_params to apply parameter setting to estimators, it is essential that calling set_params has the same effect as setting parameters using the init method. The easiest and recommended way to accomplish this is to not do any parameter validation in init. All logic behind estimator parameters, like translating string arguments into functions, should be done in fit.

Also it is expected that parameters with trailing _ are not to be set inside the init method. All and only the public attributes set by fit have a trailing . As a result the existence of parameters with trailing is used to check if the estimator has been fitted.