Skip to content

Xgboost classification#71

Merged
EmilHvitfeldt merged 4 commits into
mainfrom
xgboost-classification
Dec 17, 2024
Merged

Xgboost classification#71
EmilHvitfeldt merged 4 commits into
mainfrom
xgboost-classification

Conversation

@EmilHvitfeldt

Copy link
Copy Markdown
Member

This PR adds hard and soft predictions for classification models for xgboost

library(parsnip)
library(orbital)

# better printing
iris <- tibble::as_tibble(iris)

bt_spec <- boost_tree(mode = "classification", engine = "xgboost")
bt_fit <- fit(bt_spec, Species ~ ., iris)

orb_obj <- orbital(bt_fit, type = "class")
predict(orb_obj, iris)
#> # A tibble: 150 × 1
#>    .pred_class
#>    <chr>      
#>  1 setosa     
#>  2 setosa     
#>  3 setosa     
#>  4 setosa     
#>  5 setosa     
#>  6 setosa     
#>  7 setosa     
#>  8 setosa     
#>  9 setosa     
#> 10 setosa     
#> # ℹ 140 more rows

orb_obj <- orbital(bt_fit, type = "prob")
predict(orb_obj, iris)
#> # A tibble: 150 × 3
#>    .pred_setosa .pred_versicolor .pred_virginica
#>           <dbl>            <dbl>           <dbl>
#>  1        0.984          0.00916         0.00716
#>  2        0.982          0.00915         0.00861
#>  3        0.984          0.00916         0.00716
#>  4        0.984          0.00916         0.00716
#>  5        0.984          0.00916         0.00716
#>  6        0.984          0.00916         0.00716
#>  7        0.984          0.00916         0.00716
#>  8        0.984          0.00916         0.00716
#>  9        0.982          0.00915         0.00861
#> 10        0.984          0.00916         0.00716
#> # ℹ 140 more rows

orb_obj <- orbital(bt_fit, type = c("class", "prob"))
predict(orb_obj, iris)
#> # A tibble: 150 × 4
#>    .pred_class .pred_setosa .pred_versicolor .pred_virginica
#>    <chr>              <dbl>            <dbl>           <dbl>
#>  1 setosa             0.984          0.00916         0.00716
#>  2 setosa             0.982          0.00915         0.00861
#>  3 setosa             0.984          0.00916         0.00716
#>  4 setosa             0.984          0.00916         0.00716
#>  5 setosa             0.984          0.00916         0.00716
#>  6 setosa             0.984          0.00916         0.00716
#>  7 setosa             0.984          0.00916         0.00716
#>  8 setosa             0.984          0.00916         0.00716
#>  9 setosa             0.982          0.00915         0.00861
#> 10 setosa             0.984          0.00916         0.00716
#> # ℹ 140 more rows

Created on 2024-12-16 with reprex v2.1.0

@EmilHvitfeldt EmilHvitfeldt merged commit 2d923ac into main Dec 17, 2024
@EmilHvitfeldt EmilHvitfeldt deleted the xgboost-classification branch December 17, 2024 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant