training similar to the process with linear regressionwe will use the same preprocessed dataframe train_df_new with categoricals transformed into one hot encoded form along with other numerical attributes we also split the dataset into train and test again using the train_test_split(utility from scikit-learn the training process for decision trees is bit involved and different as compared to linear regression even though we performed cross validation while training our linear regression modelwe did not have any hyperparameters to tune in the case of decision treeswe have quite handful of them (some of which we even discussed in the previous sectionbefore we get into the specifics of obtaining optimal hyperparameterswe will look at the decisiontreeregressor from sklearn' tree module we do so by instantiating regressor object with some of the hyperparameters set as follows in [ ]dtr decisiontreeregressor(max_depth= min_samples_split= max_leaf_nodes= this code snippet prepares decisiontreeregressor object that is set to have maximum depth of maximum leaf nodes as and minimum number of samples required to split node as though there can be many morethis example outlines how hyperparameters are utilized in algorithms ##note you are encouraged to try and fit the default decision tree regressor on the training data and observe its performance on testing dataset as mentioneddecision trees have an added advantage of being interpretable we can visualize the model object using graphviz and pydot librariesas shown in the following snippet in [ ]dot_data tree export_graphviz(dtrout_file=nonegraph pydotplus graph_from_dot_data(dot_datagraph write_pdf("bikeshare pdf"the output is pdf file showcasing decision tree with hyperparameters as set in the previous step the following plot as depicted in figure - shows the root node being split on attribute and then going on until depth of is achieved there are some leaves at depth lesser than as well each node clearly marks out the attributes associated with it