Scikit-learn

Train Decision Tree in Python

Train Decision Tree in Python. Algorithm can be used in classification and regression tasks. Please make sure that there are no missing values in the training data and all values are numeric.

Please check Advanced options. There are several criterions available to measure split quality. What is more, you can control the tree structure by selecting minimum number of samples for internal node split and minimum samples in the leaf. The max depth parameter controls the depth of the tree, if it is not set then tree is trained till all leaves are pure or there are minimum samples in the internal node.

Decision Tree model can be persisted to hard disk in pickle format.

decision-treeclassificationregression

Required packages

You need below packages to use the code generated by recipe. All packages are automatically installed in MLJAR Studio.

scikit-learn>=1.0.0

Interactive recipe

You can use below interactive recipe to generate code. This recipe is available in MLJAR Studio.

In the below recipe, we assume that you have following variables available in your notebook:

  • X (type DataFrame)
  • y (type Series)

Python code

# Python code will be here

Code explanation

  1. Initialize Decision Tree object.
  2. Fit model on provided data.

Fitted object can be used to compute predictions. If you want to persist your Decision Tree, please save it to pickle file (Save to pickle recipe).

Scikit-learn cookbook

Code recipes from Scikit-learn cookbook.

Previous
Scikit-learn