There is a method "has_fit_parameter()" in sklearn.utils. It checks whether the estimator’s fit() method supports the given parameter. If the estimator supports the parameter, the method returns True; otherwise, False.
Here is an example:
>>> from sklearn.linear_model import LogisticRegression>>> from sklearn.utils.validation import has_fit_parameter>>> has_fit_parameter(LogisticRegression(), "sample_weight")True>>> has_fit_parameter(LogisticRegression(), "class_weight")False
>>> from sklearn.linear_model import LogisticRegression
>>> from sklearn.utils.validation import has_fit_parameter
>>> has_fit_parameter(LogisticRegression(), "sample_weight")
True
>>> has_fit_parameter(LogisticRegression(), "class_weight")
False
The fit() method of LogisticRegression supports sample_weight but does not support class_weight.