TransWikia.com

how to find parameters used in decision tree algorithm

Data Science Asked by A.R.SEIF on February 9, 2021

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

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

clf
# 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

UPDATE

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:

sklearn.set_config(print_changed_only=False)

Answered by desertnaut on February 9, 2021

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'}

Answered by blacksite on February 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP