Given numerical target variable, should I transform the target variable to obtain indicator matrix for multiclass classification?

Viewed 217

I am working on a multiclass classification problem using RandomForestClassifier. The target variable Y only contain one of 3 values {-1,0,1 }. I understand that numerical encoding is necessary.

However, I would like to understand if it is necessary for me to transform Y to obtain an indicator matrix like below by doing pd.get_dummies(Y) and then feed this indicator matrix into the RandomForestClassifier?

      -1.0   0.0   1.0
0        0     0     1
1        1     0     0
2        0     0     1
3        1     0     0
4        1     0     0
   ...   ...   ...
6516     1     0     0
6517     0     0     1
6518     0     0     1
6519     0     0     1
6520     1     0     0

Comparing above to feeding the untransformed target variable Y (i.e. a 1 dimensional series) into RandomForestClassifier, how would this affect the machine learning algorithm ? Would the results be different and why ?

Is the RandomForestClassifier doing different things under these 2 different scenarios ? Which approach is recommended (indicator matrix vs untransformed)?

1 Answers

I don't think there's any reason to prefer one over the other. The documentation states that you can pass an array-like of shape (n_samples,) or (n_samples, n_outputs) as y to sklearn.ensemble.RandomForestClassifier.fit().

The only difference would be how .predict() returns the predicted classes. I recommend you decide the shape of Y based on the format that you need the predictions to be in.

Aside from that, the splitting process of each estimator is the exact same.

Related