How to export regression tree with two features as matrix?
<p>I have a problem which is suitable for the application of a regression tree. The final result needs to be in matrix, though, not a tree. Is there an easy way in R or Python to export a regression tree which has only two features (in my case weight and distance) to a matrix where rows would be the weight classes, columns the distances and cell values the estimated prices? So far I could only find tree visualiziations as output. </p>

<p>I presume, that on each dimension, the tree distinguishes about 15 classes, so there are 200 to 300 cell values, in case this is important.</p>

<p>I don't really know what you mean by "exporting the tree to a matrix"; I have no idea how a regression tree could be represented as a matrix. I guess you want to show the prediction of the tree for multiple combinations of your (two) features/input variables?</p>

<p>If so, you need first need to create all combinations of interest, e.g. by utilizing <code>grid.expand</code>. Then you put the resulting data.frame as <code>newdata</code> argument of the <code>predict</code> method of the tree to get the predicted outcome. Finally you <code>cast</code> the result into matrix form.</p>

python matrix tree regression