Code Monkey home page Code Monkey logo

tm_xgboost_cla's Introduction

tm_xgboost_cla

library(tidymodels)
library(tidyverse)
source("https://github.com/rafzamb/tm_xgboost_cla/raw/master/xgboost_tune_param.R")
# Particion
cv_folds <- vfold_cv(iris, v = 2)

#Recta
Receta <- recipe(formula = Species ~ ., data =  iris)

# Modelo
xgb <- boost_tree(
  tree_depth = tune(), 
  mtry = tune(),
  stop_iter = tune(),
) %>% 
  set_engine("xgboost", 
             colsample_bytree = tune(),
             lambda = tune(),
             alpha = tune()
  ) %>% 
  set_mode("classification")

#Workflow
xgb_wf <- workflow() %>%
  add_recipe(Receta) %>%
  add_model(xgb)

#Rango de parametros
xgb_param <- 
  xgb %>%
  parameters() %>% 
  update(mtry = mtry(c(2L, 3L)),
         colsample_bytree = colsample_bytree(c(1L, 3L)),
         lambda = penalty_L2(range = c(-10, -1)),
         alpha = penalty_L1(range = c(-10, -1))
  )
#Control de optimizacion Bayes
ctrl <- control_bayes(no_improve = 2, verbose = T, save_pred = T, seed = 123)


xgb_res <- tune_bayes(xgb_wf, 
                      resamples = cv_folds,
                      iter = 3,
                      param_info = xgb_param,
                      metrics = metric_set(f_meas),
                      control = ctrl,
                      initial = 8
)
#> 
#> >  Generating a set of 8 initial parameter results
#> ! Fold1: preprocessor 1/1, model 2/8: `early_stop` was reduced to 14.
#> ! Fold1: preprocessor 1/1, model 6/8: `early_stop` was reduced to 14.
#> ! Fold1: preprocessor 1/1, model 8/8: `early_stop` was reduced to 14.
#> ! Fold2: preprocessor 1/1, model 2/8: `early_stop` was reduced to 14.
#> ! Fold2: preprocessor 1/1, model 6/8: `early_stop` was reduced to 14.
#> ! Fold2: preprocessor 1/1, model 8/8: `early_stop` was reduced to 14.
#> v Initialization complete
#> 
#> Optimizing f_meas using the expected improvement
#> 
#> -- Iteration 1 -----------------------------------------------------------------
#> 
#> i Current best:      f_meas=0.9666 (@iter 0)
#> i Gaussian process model
#> v Gaussian process model
#> i Generating 5000 candidates
#> i Predicted candidates
#> i mtry=3, tree_depth=12, stop_iter=13, colsample_bytree=3, lambda=1.07e-10,
#>   alpha=1.15e-05
#> i Estimating performance
#> v Estimating performance
#> (x) Newest results:  f_meas=0.9666 (+/-0.00394)
#> 
#> -- Iteration 2 -----------------------------------------------------------------
#> 
#> i Current best:      f_meas=0.9666 (@iter 0)
#> i Gaussian process model
#> v Gaussian process model
#> i Generating 5000 candidates
#> i Predicted candidates
#> i mtry=3, tree_depth=3, stop_iter=3, colsample_bytree=3, lambda=0.00124,
#>   alpha=2.21e-08
#> i Estimating performance
#> v Estimating performance
#> (x) Newest results:  f_meas=0.9603 (+/-0.0103)
#> ! No improvement for 2 iterations; returning current results.
autoplot(xgb_res) + theme(legend.position = "top")

tm_xgboost_cla's People

Contributors

rafzamb avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.