Three applications of caret package: Modeling and parameter optimization

Source: Internet
Author: User

Original address: http://xccds.github.io/2011/09/caret_1976.html/

When modeling, the parameters of the model need to be optimized, and the main function commands in the caret package are train.

First we get the sample data after feature selection, and divide it into training samples and test samples.
Newdata4=newdata3[,profile$optvariables]
Intrain = Createdatapartition (mdrrclass, p = 3/4, list = FALSE)
Trainx = Newdata4[intrain,]
TESTX = Newdata4[-intrain,]
Trainy = Mdrrclass[intrain]
testy = Mdrrclass[-intrain] Then define the model training parameters, method determine the multiple cross-examination of the sampling methods, number determined the division of the weight, repeats determined the number of repetitions.

Fitcontrol = Traincontrol (method = "REPEATEDCV", Number = ten, repeats = 3,returnresamp = "All") determines the parameter selection range, in this case the model is prepared using the GBM algorithm, the corresponding The parameters are as follows three
Gbmgrid = Expand.grid (. interaction.depth = C (1, 3),. N.trees = C (d, B, D, D, D, +),. Shrinkage = 0.1) using the train function Training, using the modeling method to enhance the decision tree method,
GbmFit1 = Train (Trainx,trainy,method = "GBM", Trcontrol = Fitcontrol,tunegrid = Gbmgrid,verbose = FALSE) From the result can be observed interacti On.depth the highest accuracy when taking 1,n.trees 150

Interaction.depth n.trees accuracy kappa accuracy SD Kappa SD
1 50 0.822 0.635 0.0577 0.118
1 100 0.824 0.639 0.0574 0.118
1 150 0.826 0.643 0.0635 0.131
1 200 0.824 0.64 0.0605 0.123
1 250 0.816 0.623 0.0608 0.124
1 300 0.824 0.64 0.0584 0.119
3 50 0.816 0.621 0.0569 0.117
3 100 0.82 0.631 0.0578 0.117
3 150 0.815 0.621 0.0582 0.117
3 200 0.82 0.63 0.0618 0.125
3 250 0.813 0.617 0.0632 0.127
3 300 0.812 0.615 0.0622 0.126

The same graphical observation
Plot (GBMFIT1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.