Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix base_score problem. #66

Merged
merged 8 commits into from
Jul 14, 2020
Merged

fix base_score problem. #66

merged 8 commits into from
Jul 14, 2020

Conversation

JiaxiangBU
Copy link
Contributor

Here is the reproducible minimal example for testing.

library(xgboost)
#> Warning: 程辑包'xgboost'是用R版本3.6.1 来建造的
library(tidyverse)
#> Registered S3 methods overwritten by 'ggplot2':
#>   method         from 
#>   [.quosures     rlang
#>   c.quosures     rlang
#>   print.quosures rlang
#> Warning: 程辑包'dplyr'是用R版本3.6.1 来建造的
train_data <- mtcars %>%
  rename(y = am)
dtrain <-
  xgb.DMatrix(data = as.matrix(train_data %>% select(-y))
              , label = train_data$y)
xgb_model <- xgb.train(
  data = dtrain,
  nround = 10,
  seed = 1,
  max_depth = 1,
  objective = "binary:logistic",
  base_score = mean(train_data$y) # fix uncalibration problem
)
pred_from_model <- predict(xgb_model, newdata = dtrain)
library(sqldf)
#> Warning: 程辑包'sqldf'是用R版本3.6.1 来建造的
#> 载入需要的程辑包:gsubfn
#> Warning: 程辑包'gsubfn'是用R版本3.6.1 来建造的
#> 载入需要的程辑包:proto
#> Warning: 程辑包'proto'是用R版本3.6.1 来建造的
#> 载入需要的程辑包:RSQLite
#> Warning: 程辑包'RSQLite'是用R版本3.6.1 来建造的
library(tidypredict)
pred_from_tidypredict <-
  tidypredict_sql(xgb_model, dbplyr::simulate_dbi()) %>%
  paste("select ", ., " from mtcars") %>%
  str_replace("LN", "log") %>% 
  sqldf() %>%
  pull
(pred_from_model - pred_from_tidypredict) %>% abs %>% mean
#> [1] 1.464673e-08

Created on 2019-10-20 by the reprex package (v0.3.0)

@topepo
Copy link
Member

topepo commented Apr 3, 2020

Please write some test cases for this.

R/model-xgboost.R Outdated Show resolved Hide resolved
@topepo
Copy link
Member

topepo commented Jul 14, 2020

Thanks for doing this.

@topepo topepo merged commit c16d146 into tidymodels:master Jul 14, 2020
@github-actions
Copy link

github-actions bot commented Mar 6, 2021

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants