Extract Coefficient Information from Models

# S3 method for xgb.Booster
extract.coef(model, feature_names = NULL,
  removeNonSelected = TRUE, ...)

Arguments

model

Model object from which to extract information.

feature_names

Names of coefficients

removeNonSelected

If TRUE (default) do not return the non-selected (0) coefficients

...

Further arguments

Value

A data.frame containing the coefficient, the standard error and the variable name.

Details

Gets the coefficient values and variable names from a model. Since xgboost does not have standard errors, those will just be NA.

Examples

library(xgboost) data(diamonds, package='ggplot2') diaX <- useful::build.x(price ~ carat + cut + x, data=diamonds, contrasts=FALSE) diaY <- useful::build.y(price ~ carat + cut + x, data=diamonds) xg1 <- xgboost(data=diaX, label=diaY, booster='gblinear', objective='reg:linear', eval_metric='rmse', nrounds=50 )
#> [1] train-rmse:3431.926270 #> [2] train-rmse:3110.120850 #> [3] train-rmse:2834.771729 #> [4] train-rmse:2602.429932 #> [5] train-rmse:2406.225098 #> [6] train-rmse:2241.269775 #> [7] train-rmse:2103.484863 #> [8] train-rmse:1989.205078 #> [9] train-rmse:1895.113037 #> [10] train-rmse:1818.168701 #> [11] train-rmse:1755.667480 #> [12] train-rmse:1705.199341 #> [13] train-rmse:1664.665649 #> [14] train-rmse:1632.252075 #> [15] train-rmse:1606.439453 #> [16] train-rmse:1585.940308 #> [17] train-rmse:1569.709351 #> [18] train-rmse:1556.883301 #> [19] train-rmse:1546.755493 #> [20] train-rmse:1538.773560 #> [21] train-rmse:1532.486816 #> [22] train-rmse:1527.534302 #> [23] train-rmse:1523.632690 #> [24] train-rmse:1520.557983 #> [25] train-rmse:1518.135010 #> [26] train-rmse:1516.224365 #> [27] train-rmse:1514.712769 #> [28] train-rmse:1513.516724 #> [29] train-rmse:1512.565674 #> [30] train-rmse:1511.812622 #> [31] train-rmse:1511.209839 #> [32] train-rmse:1510.725586 #> [33] train-rmse:1510.338745 #> [34] train-rmse:1510.024536 #> [35] train-rmse:1509.764771 #> [36] train-rmse:1509.555664 #> [37] train-rmse:1509.381226 #> [38] train-rmse:1509.228882 #> [39] train-rmse:1509.106812 #> [40] train-rmse:1508.997559 #> [41] train-rmse:1508.907593 #> [42] train-rmse:1508.827148 #> [43] train-rmse:1508.754150 #> [44] train-rmse:1508.691162 #> [45] train-rmse:1508.631348 #> [46] train-rmse:1508.575073 #> [47] train-rmse:1508.521484 #> [48] train-rmse:1508.474243 #> [49] train-rmse:1508.427124 #> [50] train-rmse:1508.381714
#> # A tibble: 8 x 3 #> Value SE Coefficient #> <dbl> <dbl> <chr> #> 1 8011. NA carat #> 2 -3168. NA cutFair #> 3 -2050. NA cutGood #> 4 -1724. NA cutPremium #> 5 -1657. NA cutVery Good #> 6 -1373. NA cutIdeal #> 7 -135. NA (Intercept) #> 8 -72.7 NA x
extract.coef(xg1, feature_names=colnames(diaX))
#> # A tibble: 8 x 3 #> Value SE Coefficient #> <dbl> <dbl> <chr> #> 1 8011. NA carat #> 2 -3168. NA cutFair #> 3 -2050. NA cutGood #> 4 -1724. NA cutPremium #> 5 -1657. NA cutVery Good #> 6 -1373. NA cutIdeal #> 7 -135. NA (Intercept) #> 8 -72.7 NA x