Question: How can I update the code below to: a ) Manually specify the cost complexity paramente with a specific value. for example, create a regular
How can I update the code below to:
a Manually specify the cost complexity paramente with a specific value. for example, create a regular grid with only one value for the complexity parameter?
b Prune the tree. Create a regular or random grid with some values for the cost complexity parameter, rerun the hyperparameter tuning step, and investigate the performance of the different hyperparameter values?
c Select the best one according to for example ROCAUC or Accuracy?
d Create the training set, validation, and test prediction using the pruned decision tree.
e Visualize the pruned decision tree?
dataset readcsvCensuscsv
strdataset
dataset$Income asfactordataset$Income
dataset$Education.num asfactordataset$Education.num
dataset$Race asfactordataset$Race
dataset$Sex asfactordataset$Sex
dataset selectdataset
dataset$Income factordataset$Income, levels cLow"High"
strdataset
summarydataset
plotintrodataset
set.seed
datasplit initialsplitdata dataset,
prop
strata Income
datatrain trainingdatasplit
datatest testingdatasplit
targetvar "Income"
modelform Income ~ Age Education.num Race Sex Hours.per.week
positiveclass 'Low'
modelrecipe recipeformula modelform, data datatrain
stepnovelallnominalpredictors
stepunknownallpredictorsallnumeric
stepdummyallnominalpredictors
stepzvallpredictors
classtreemodel
decisiontreecostcomplexity tune
setenginerpart
setmodeclassification
classtreeworkflow workflow
addrecipemodelrecipe
addmodelclasstreemodel
allmodels workflowset
preproc listmodelrecipe
models listclasstreerpart classtreemodel
set.seed
cvfolds vfoldcvdatatrain, v
control controlresamplessaveworkflow TRUE,
savepred TRUE,
eventlevel "second"
classificationmetrics metricsetyardstick::accuracy,
yardstick::kap,
yardstick::rocauc,
yardstick::mnlogloss,
yardstick::sens
yardstick::spec,
yardstick::fmeas,
yardstick::precision,
yardstick::recall
tGridrandom gridrandomcostcomplexity
size
modelstrained allmodels
workflowmaptunegrid",
resamples cvfolds,
grid tGridrandom,
metrics classificationmetrics,
verbose TRUE,
control control
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
