fstermann / mlr-mini

MIT License
0 stars 2 forks source link

Models #7

Open m-muecke opened 1 year ago

m-muecke commented 1 year ago

Tasks

Description

Models represent a trained machine learning model that can be used for prediction. They should provide information about the algorithm used to get the result, a way to inspect the result, and a way to make predictions.

inducer(model.xgb)  # get the "xgb" used to train this model
#> Inducer: "XGBoost"
#> Configuration: nrounds = 10, verbose = 0

configuration(model.xgb)
#> $nrounds
#> [1] 10
#> 
#> $verbose
#> [1] 0

modelObject(model.xgb)  # get the object generated by xgboost::xgboost
#> ##### xgb.Booster
#> raw: 16.1 Kb 
#> call:
#>   xgb.train(params = params, data = dtrain, nrounds = nrounds, 
#>     watchlist = watchlist, verbose = verbose, print_every_n = print_every_n, 
#>     early_stopping_rounds = early_stopping_rounds, maximize = maximize, 
#>     save_period = save_period, save_name = save_name, xgb_model = xgb_model, 
#>     callbacks = callbacks)
#> params (as set within xgb.train):
#>   validate_parameters = "TRUE"
#> xgb.attributes:
#>   niter
#> callbacks:
#>   cb.evaluation.log()
#> niter: 10
#> nfeatures : 1 
#> evaluation_log:
#>     iter train_rmse
#>        1   37.25719
#>        2   28.61702
#> ---                
#>        9   12.29622
#>       10   12.03218

modelInfo(model.xgb)
#> $training.time.sec
#> [1] 15

predict(model.xgb, newdata = data.frame(speed = 10))
#> [1] 23.76096

prediction <- predict(model.xgb, newdata = cars.data[c(1, 2, 3, 4), ])

prediction
#>    prediction truth
#> 1:   5.710046     2
#> 2:   5.710046    10
#> 3:  12.451396     4
#> 4:  12.451396    22