I built a pipeline including a DecisionTreeClassifier(dt) like this
val pipeline = new Pipeline().setStages(Array(labelIndexer, featureIndexer, dt, labelConverter))
Then I used this pipeline as the estimator in a CrossValidator in order to get a model with the best set of hyperparameters like this
val c_v = new CrossValidator().setEstimator(pipeline).setEvaluator(new MulticlassClassificationEvaluator().setLabelCol("indexedLabel").setPredictionCol("prediction")).setEstimatorParamMaps(paramGrid).setNumFolds(5)
Finally, I could train a model on a training test with this crossvalidator
val model = c_v.fit(train)
But the question is, I want to view the best trained decision tree model with the parameter .toDebugTree
of DecisionTreeClassificationModel
. But model is a CrossValidatorModel
. Yes, you can use model.bestModel
, but it is still of type Model
, you cannot apply .toDebugTree
to it. And also I assume the bestModel is still a pipline including labelIndexer
, featureIndexer
, dt
, labelConverter
.
So does anyone know how I can obtain the decisionTree model from the model fitted by the crossvalidator
, which I could view the actual model by toDebugString
? Or is there any workaround that I can view the decisionTree model?