Skip to contents

A family of constructor functions that return ready-to-use modelblueprint objects for common R model types.

Usage

mb_lm_regression()

mb_lm_classification()

mb_glm_regression()

mb_glm_binomial()

mb_glm_poisson()

mb_glm_poisson_freq()

mb_rpart_regression()

mb_rpart_classification()

mb_rf_regression()

mb_rf_classification()

mb_xgb_regression()

mb_xgb_classification()

mb_h2o_regression()

mb_h2o_classification()

mb_h2o_glm_large(n = 5000L)

Arguments

n

[integer(1)] Number of rows to simulate. Default 5000L is enough to see the caching benefit of the dashboard. Use 50000L or more to stress-test prediction latency on large models.

Value

A modelblueprint object.

Details

Regression target: mpg (continuous) — synthetic mtcars-like data, 75/25 train/test split.

Classification target: vs (binary 0/1) — same synthetic dataset.

Frequency target: claim_freq (claims per unit exposure) — synthetic car insurance dataset with ~5,000 rows, 70/15/15 train/test/holdout split. The underlying model is a Poisson GLM on nclaims with offset(log(exposure)); a post_process_fun converts predicted counts to predicted frequency before returning.

Functions that wrap optional packages (rpart, randomForest, xgboost, h2o) will error informatively if the package is not installed. H2O functions also require a Java installation and will start an H2O cluster automatically.

post_process_fun is set on classification models that return a probability matrix (rpart, randomForest) so that predict() always returns a plain numeric vector of P(class = 1), and on mb_glm_poisson_freq() to convert predicted counts to predicted claim frequency.

Examples

mb <- mb_lm_regression()
predict(mb, mb@test)
#> [1] 12.47164 19.87627 17.62189 22.70162 17.69608 17.40226 22.73514 14.49673
one_way(mb, var = "wt")
mb_cls <- mb_glm_binomial() predict(mb_cls, mb_cls@test) # returns probabilities in 0 to 1 #> [1] 0.08224707 0.13481148 0.09740143 0.08765559 0.15740888 0.17504665 0.02249779 #> [8] 0.09934203 mb_freq <- mb_glm_poisson_freq() predict(mb_freq, mb_freq@test) # returns predicted claim frequency #> [1] 0.19382248 0.10658090 0.10694054 0.09385898 0.08595710 0.20434500 #> [7] 0.09392118 0.10928043 0.07650397 0.15596028 0.10281719 0.08506253 #> [13] 0.11187185 0.12760656 0.09064209 0.14746947 0.13255053 0.19146416 #> [19] 0.17808959 0.11900847 0.06171092 0.12954129 0.08248569 0.13501184 #> [25] 0.08753549 0.15717189 0.09562213 0.09997402 0.10052712 0.16786549 #> [31] 0.17792211 0.05927614 0.27458784 0.06334559 0.09447184 0.19844428 #> [37] 0.11113061 0.16277388 0.07549623 0.16783565 0.17376406 0.05020352 #> [43] 0.13493541 0.11141841 0.34031644 0.14930871 0.11437541 0.12842017 #> [49] 0.07089983 0.12663936 0.04745655 0.11275441 0.10874910 0.09802899 #> [55] 0.14678280 0.09765556 0.10318543 0.06223689 0.09155569 0.15211386 #> [61] 0.12475143 0.16847649 0.10590410 0.18339251 0.16004663 0.12392568 #> [67] 0.12583716 0.16092132 0.08813814 0.08153871 0.15400546 0.11423266 #> [73] 0.15661742 0.10688710 0.07807253 0.16051866 0.15031445 0.10821535 #> [79] 0.10668316 0.11919940 0.07853964 0.21750375 0.08782340 0.22238221 #> [85] 0.10466487 0.08391792 0.11615732 0.18541600 0.08561709 0.16994752 #> [91] 0.10770610 0.20109797 0.14758234 0.09487624 0.10474987 0.15178615 #> [97] 0.10420780 0.07743842 0.15647662 0.09170330 0.09350194 0.17744672 #> [103] 0.13807636 0.13563039 0.08396971 0.10741677 0.16206568 0.07729882 #> [109] 0.06082942 0.06576094 0.08205123 0.05639437 0.17194089 0.09790480 #> [115] 0.06229392 0.11125655 0.15886107 0.16795212 0.09408968 0.14954923 #> [121] 0.11048666 0.15551137 0.18841142 0.19114936 0.10164405 0.13403315 #> [127] 0.33816563 0.20023285 0.18779706 0.12287853 0.08443396 0.20100402 #> [133] 0.16773611 0.09547209 0.07406929 0.08480831 0.13562807 0.19348243 #> [139] 0.16232069 0.13352625 0.06620941 0.09136995 0.15060705 0.16117359 #> [145] 0.14218061 0.07553630 0.10766048 0.14654560 0.07756119 0.16568847 #> [151] 0.08489955 0.11496500 0.09424389 0.12405811 0.12009183 0.11884356 #> [157] 0.12297907 0.19988857 0.14501161 0.09780964 0.21095768 0.07686430 #> [163] 0.09580506 0.13636593 0.11743398 0.11666470 0.06731129 0.18730849 #> [169] 0.11735766 0.16569549 0.16234973 0.10088254 0.08031201 0.10240667 #> [175] 0.14649723 0.16655285 0.10740741 0.21646771 0.10257089 0.08737172 #> [181] 0.07487564 0.08001029 0.08317696 0.12211836 0.16132788 0.10999938 #> [187] 0.11750284 0.15467751 0.07974665 0.10990354 0.05989971 0.13768327 #> [193] 0.22363776 0.11966949 0.14860776 0.19685664 0.14239418 0.17138902 #> [199] 0.15613542 0.17322554 0.22167510 0.09469618 0.06702706 0.05980236 #> [205] 0.17548147 0.11783347 0.10643962 0.15685131 0.18757073 0.09442749 #> [211] 0.07634066 0.13815400 0.09715609 0.08588323 0.10130617 0.11690982 #> [217] 0.10801144 0.07499134 0.06942371 0.22519431 0.15185307 0.11937924 #> [223] 0.14032113 0.13772591 0.04756840 0.11748447 0.10432682 0.12196657 #> [229] 0.15169899 0.10360311 0.17797698 0.17224455 0.12055637 0.13724324 #> [235] 0.18642126 0.16790214 0.07966429 0.12056604 0.10502999 0.07171500 #> [241] 0.20375027 0.16561486 0.16031416 0.07639233 0.08541568 0.16631657 #> [247] 0.07570388 0.21141460 0.18845591 0.09781268 0.17064217 0.10373153 #> [253] 0.10032960 0.20877893 0.06840439 0.09624369 0.12134191 0.18958922 #> [259] 0.09451956 0.15482185 0.05851585 0.11527980 0.24005234 0.05801490 #> [265] 0.21194676 0.09165637 0.09837195 0.10989325 0.12922225 0.12387022 #> [271] 0.17964984 0.07961927 0.11841905 0.21070635 0.17612940 0.17364475 #> [277] 0.10932062 0.07519247 0.11380273 0.14223866 0.17431245 0.10760861 #> [283] 0.07510916 0.10608426 0.14598664 0.15146917 0.19932484 0.05558390 #> [289] 0.15599152 0.08665712 0.09259322 0.12931733 0.08067979 0.19790038 #> [295] 0.08233686 0.14029275 0.10043273 0.13882808 0.12043719 0.10658444 #> [301] 0.14913900 0.16914154 0.15861481 0.11207205 0.15552631 0.11551269 #> [307] 0.09371780 0.15892981 0.07015018 0.17791855 0.11978057 0.12285786 #> [313] 0.21404017 0.08461127 0.17293045 0.07133187 0.11591141 0.08664875 #> [319] 0.18265569 0.14954855 0.15337846 0.06204643 0.11958670 0.13737633 #> [325] 0.08606888 0.07154595 0.11518649 0.22278306 0.13728771 0.10182384 #> [331] 0.09138705 0.08400125 0.19714065 0.15669906 0.06127398 0.05790078 #> [337] 0.15834479 0.10864862 0.06539213 0.14153314 0.14378918 0.16875730 #> [343] 0.11759042 0.09452681 0.13043209 0.08428408 0.15353675 0.12569062 #> [349] 0.28784225 0.10323839 0.09297524 0.09318080 0.15135143 0.12575359 #> [355] 0.09171874 0.15739481 0.10297667 0.10916818 0.08925036 0.12153652 #> [361] 0.21459669 0.19255372 0.08013622 0.10458494 0.11533624 0.07978310 #> [367] 0.08074396 0.11409341 0.26845193 0.11903062 0.12407256 0.16479584 #> [373] 0.07056786 0.07162361 0.10491155 0.11225645 0.09028046 0.07295413 #> [379] 0.15104778 0.17875288 0.22252120 0.08035515 0.23351230 0.12876647 #> [385] 0.05393931 0.12685936 0.09422762 0.09300778 0.14848575 0.12240644 #> [391] 0.06501740 0.10462908 0.17017034 0.14246067 0.10779501 0.09999406 #> [397] 0.16198314 0.21168954 0.12500673 0.10802091 0.09136568 0.08427345 #> [403] 0.13024186 0.26671153 0.08411957 0.11332266 0.12864527 0.16717382 #> [409] 0.08778206 0.10441617 0.09406155 0.08748466 0.10084412 0.12669088 #> [415] 0.13355809 0.08671270 0.17463921 0.17150774 0.11890171 0.10271591 #> [421] 0.10580220 0.05010048 0.13123184 0.18856182 0.09183338 0.15110523 #> [427] 0.16913872 0.10726249 0.15981770 0.10526288 0.09426038 0.09527589 #> [433] 0.09696069 0.09648101 0.09738093 0.08845853 0.11885735 0.10439691 #> [439] 0.14289352 0.06796832 0.23235322 0.07549431 0.10454305 0.13064298 #> [445] 0.08158312 0.12475219 0.16120108 0.11193310 0.09761706 0.07737143 #> [451] 0.10338265 0.08368886 0.08636464 0.12450845 0.10062686 0.13848589 #> [457] 0.12187660 0.08065780 0.18803284 0.15548739 0.11195717 0.11061596 #> [463] 0.14948297 0.13960236 0.09327147 0.10704743 0.07094630 0.15847826 #> [469] 0.06140976 0.07075127 0.11151248 0.15230173 0.10352216 0.07592003 #> [475] 0.14145361 0.17220648 0.15119346 0.15831678 0.09192842 0.10548059 #> [481] 0.15220412 0.07347833 0.05813772 0.12215643 0.19937506 0.13676172 #> [487] 0.16435033 0.10578583 0.18645478 0.11041199 0.07272768 0.12312613 #> [493] 0.16058143 0.13987685 0.07948547 0.12801383 0.08878144 0.13901369 #> [499] 0.18139095 0.11891630 0.15108044 0.12610783 0.06810748 0.06012389 #> [505] 0.12805979 0.12870470 0.08675794 0.08700755 0.10564026 0.07338340 #> [511] 0.12825494 0.17194347 0.16064253 0.11507827 0.13406667 0.18600475 #> [517] 0.20055843 0.09606113 0.09327208 0.15358290 0.09309377 0.08142335 #> [523] 0.14811086 0.17219919 0.14798524 0.14412353 0.07768649 0.12531087 #> [529] 0.10945921 0.12688503 0.16667841 0.24943786 0.18522386 0.12335797 #> [535] 0.09068968 0.09006938 0.09072907 0.10763484 0.05647152 0.07889359 #> [541] 0.19216828 0.14005069 0.07836834 0.11328113 0.11727812 0.10943164 #> [547] 0.08161285 0.07929578 0.12556261 0.10088052 0.09503536 0.17233305 #> [553] 0.14278750 0.15783878 0.15240582 0.08685942 0.16369418 0.06466362 #> [559] 0.11604140 0.09918029 0.15451402 0.13235185 0.08235560 0.17259802 #> [565] 0.16748096 0.14913938 0.08507710 0.09717250 0.20509002 0.12642999 #> [571] 0.07495389 0.13287735 0.24596267 0.07921172 0.09076244 0.14477725 #> [577] 0.16183474 0.14766776 0.08478130 0.14783413 0.14866295 0.11744646 #> [583] 0.09954526 0.08532788 0.08687364 0.13687768 0.11220232 0.18675330 #> [589] 0.20510269 0.08272770 0.11170563 0.14720040 0.07049268 0.14511248 #> [595] 0.16334632 0.15055366 0.19561359 0.16498102 0.16395628 0.10438184 #> [601] 0.10581610 0.15739900 0.10259384 0.10648239 0.06311289 0.14820967 #> [607] 0.15823263 0.14349158 0.27209391 0.12238513 0.12155138 0.13852954 #> [613] 0.12834353 0.10021140 0.08941994 0.18821103 0.18291439 0.11087953 #> [619] 0.08834233 0.12367291 0.08846018 0.10731315 0.14085343 0.09965526 #> [625] 0.17198879 0.08544115 0.20355988 0.13057129 0.10736541 0.07730216 #> [631] 0.16570412 0.09719241 0.17158994 0.14476607 0.17447150 0.14074625 #> [637] 0.15374302 0.07446122 0.17579892 0.07801613 0.22255366 0.09063845 #> [643] 0.07485713 0.10988842 0.10570868 0.14920047 0.10967017 0.15745439 #> [649] 0.08853460 0.07450968 0.07250421 0.12142539 0.08576688 0.13025184 #> [655] 0.11327508 0.06746616 0.10897995 0.17724549 0.06456823 0.09338644 #> [661] 0.21068847 0.15364513 0.10007524 0.06272267 0.17471871 0.07543682 #> [667] 0.08487865 0.15856802 0.14622655 0.11604124 0.08256648 0.21438728 #> [673] 0.09408382 0.26650829 0.08794244 0.12416048 0.06765407 0.11578371 #> [679] 0.12116131 0.15806090 0.18624643 0.13655447 0.17120684 0.19598744 #> [685] 0.14528140 0.08784241 0.09202142 0.11628142 0.14798102 0.15798701 #> [691] 0.08945130 0.14212032 0.15102171 0.16134653 0.12846341 0.17725364 #> [697] 0.19876581 0.07086493 0.06114510 0.06634963 0.09011262 0.10750843 #> [703] 0.16430877 0.13613926 0.14400793 0.06119931 0.09093017 0.12490076 #> [709] 0.16207130 0.16824519 0.09628876 0.08275105 0.12728273 0.13875957 #> [715] 0.22344931 0.06392330 0.16737278 0.12281243 0.10264025 0.07134981 #> [721] 0.14555723 0.07593356 0.11930124 0.14513775 0.08214608 0.15520105 #> [727] 0.24088410 0.16199289 0.06705567 0.10380913 0.13423952 0.15058963 #> [733] 0.18197296 0.09154438 0.12414549 0.14943184 0.07487166 0.06950519 #> [739] 0.17188801 0.17066571 0.23798558 0.08409603 0.10581725 0.10176818 #> [745] 0.14630829 0.10966149 0.25548870 0.08895935 0.08308706 0.11885429 one_way(mb_freq, var = "driver_age", predictions = TRUE)