I use a machine learning algorithm, for example decision tree classifier similar to this:

from sklearn import tree
X = [[0, 0], [1, 1]]
Y = [0, 1]
clf = tree.DecisionTreeClassifier()
clf = clf.fit(X, Y)
clf.predict([[2., 2.]])

How to find out what parameters are used?


2 Answers 2


Just type clf after defining it; in your case it gives:

# result:

DecisionTreeClassifier(ccp_alpha=0.0, class_weight=None, criterion='gini',
                       max_depth=None, max_features=None, max_leaf_nodes=None,
                       min_impurity_decrease=0.0, min_impurity_split=None,
                       min_samples_leaf=1, min_samples_split=2,
                       min_weight_fraction_leaf=0.0, presort='deprecated',
                       random_state=None, splitter='best')

i.e. all arguments with their default values, since you did not specify anything in the definition clf = tree.DecisionTreeClassifier().

You can get the parameters of any algorithm in scikit-learn in a similar way.

Tested with scikit-learn v0.22.2


As Ben Reiniger correctly points out in the comment below, from scikit-learn v0.23 onwards, we need to set the display configuration first in order for this to work:

  • 3
    $\begingroup$ This won't display the default parameters from v0.23, unless you set the configuration parameter print_changed_only=False, with config_context or set_config. $\endgroup$
    – Ben Reiniger
    Commented Sep 25, 2020 at 22:54

You can also use the get_params method define for (I believe) all scikit-learn models, as they inherit from sklearn.base.BaseEstimator. This makes it very easily to create new instances of certain models (although you could also use sklearn.base.clone), or save the parameters for later evaluation.

>>> clf.get_params()
{'ccp_alpha': 0.0, 'class_weight': None, 'criterion': 'gini', 'max_depth': None, 'max_features': None, 'max_leaf_nodes': None, 'min_impurity_decrease': 0.0, 'min_impurity_split': None, 'min_samples_leaf': 1, 'min_samples_split': 2, 'min_weight_fraction_leaf': 0.0, 'presort': 'deprecated', 'random_state': None, 'splitter': 'best'}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.