1
$\begingroup$

I want to use sklearns DecisionTreeClassifier for sentiment analysis. I am fully aware that a decision tree is probably not a good model for this kind of task, but I want to try it anyways for the purpose of comparison.

My text data will be vectorized by one-hot endcoding. This of course means that the data will be very high-dimensional. For that reason, I am interested in how one would set the parameters of the DecisionTreeClassifier (especially the max_depth parameter) so that the classifier works reasonably well and the tree does not become enormous.

Here is my code:

from sklearn.tree import DecisionTreeClassifier
from sklearn.feature_extraction.text import CountVectorizer
 
vectorizer = CountVectorizer(max_df=0.90, min_df = 2, stop_words='english', binary = True)
model = DecisionTreeClassifier()
    
X_train = vectorizer.fit_transform(text_data)
y_train = target_values
model.fit(X_train, y_train)
$\endgroup$
1
  • $\begingroup$ You mention both having a classifier that works well, and a tree that is not too deep (perhaps because you want it to be interpretable). This can be a tricky tradeoff to navigate - is one of those more important to you than the other? How deep is "too deep" for your purposes? $\endgroup$ Mar 25, 2021 at 13:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.