NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

library(caTools)
library(xgboost)

# creating a function to find best nrounds, using 70% data to train and 30% data to validate
validation_fun <- function(temp_train, temp_target)
{
targte_no. <- paste('targte',fun_call,sep='_')
cat("n",'training the model for',targte_no., 'to get the optimum number of iterations',"n")

#split the training for training and validation
set.seed(3000)

spl = sample.split(temp_target, SplitRatio = 0.70)
cv_train_data = subset(temp_train, spl == TRUE)
cv_train_target <- temp_target[spl==TRUE] # it will be used in xgb.DMatrix

cv_test_data = subset(temp_train, spl == FALSE)
cv_test_target <- temp_target[spl==FALSE] # it will be used in xgb.DMatrix


# summary of target variables
# summary(temp_target)
# summary(cv_train_target)
# summary(cv_test_target)

####### now the modelling part
dtrain<-xgb.DMatrix(data=data.matrix(cv_train_data),label=data.matrix(cv_train_target))
dval<-xgb.DMatrix(data=data.matrix(cv_test_data),label=data.matrix(cv_test_target))
watchlist<-list(val=dval)


param = list(objective ="reg:linear",
eval_metric = 'rmse',
booster = "gbtree",
"max_depth" = 10,
"eta" = 0.1,
"subsample" = 1,
"colsample_bytree" =1 ,
"min_child_weight" = 1)

set.seed(600)
bst = xgb.train(param=param,
data =dtrain,
nrounds=10000,
verbose = 1,
early_stopping_rounds = 50,
watchlist = watchlist ,
print_every_n = 20,
maximize = FALSE)

# saving the results to a file
cat ("n",fun_call, 'cv_best_nrounds:', bst$best_iteration,'nrounds:', as.integer(bst$best_iteration/0.7),
'cv_rmse_score:', bst$best_score,
file = "F:/Data Science/impulse/nrounds.txt", append = TRUE)


# printing to console
cat("n",'-------------------------------- CV Results -----------------------------------------')
cat ("n",'cv_best_nrounds:', bst$best_iteration,'nrounds:', as.integer(bst$best_iteration/0.7),
'cv_rmse_score:', bst$best_score )
cat("n",'-------------------------------------------------------------------------------------')

assign("final_nrounds",as.integer(bst$best_iteration/0.7),envir =.GlobalEnv)

cat("n",'Now training the actual model for',targte_no.,'which will be saved for later use',"n")

}

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.