I have a data set with categorical variables. I have defined a decision tree algorithm and transformed these columns to numerical equivalent using one hot encoding functionality in sklearn:
Create Decision Tree classifer object:
clf2 = DecisionTreeClassifier(criterion = 'entropy') pipe = make_pipeline(column_trans, clf2) # (1) pipe.fit(X_train2,y_train2)
column_trans = make_column_transformer( (OneHotEncoder(),['ShelveLoc','Urban','US']), remainder = 'passthrough')
Now when I built the decision tree without using sklearn but using pandas directly for categorical feature encoding, I was able to find the suitable candidates for alpha to prune the decision tree by
path = clf.cost_complexity_pruning_path(X_train, y_train) ccp_alphas = path.ccp_alphas ccp_alphas = ccp_alphas[:-1] #remove max value of alpha
where as now given that my model is baked into pipe argument in (1) when I try to find candidate alphas
path = pipe.cost_complexity_pruning_path(X_train2, y_train2)
I get an error message saying pipe does not have the attribute called cost complexity pruning. and looking at all the attributes available to pipe, I can't find cost complexity pruning as well.
Is it only possible to do cost complexity pruning if you are building the model without using the pipe functionality in Sklearn?