-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathsearch.json
1 lines (1 loc) · 104 KB
/
search.json
1
[{"path":[]},{"path":"https://tidypredict.tidymodels.org/CODE_OF_CONDUCT.html","id":"our-pledge","dir":"","previous_headings":"","what":"Our Pledge","title":"Contributor Covenant Code of Conduct","text":"members, contributors, leaders pledge make participation community harassment-free experience everyone, regardless age, body size, visible invisible disability, ethnicity, sex characteristics, gender identity expression, level experience, education, socio-economic status, nationality, personal appearance, race, religion, sexual identity orientation. pledge act interact ways contribute open, welcoming, diverse, inclusive, healthy community.","code":""},{"path":"https://tidypredict.tidymodels.org/CODE_OF_CONDUCT.html","id":"our-standards","dir":"","previous_headings":"","what":"Our Standards","title":"Contributor Covenant Code of Conduct","text":"Examples behavior contributes positive environment community include: Demonstrating empathy kindness toward people respectful differing opinions, viewpoints, experiences Giving gracefully accepting constructive feedback Accepting responsibility apologizing affected mistakes, learning experience Focusing best just us individuals, overall community Examples unacceptable behavior include: use sexualized language imagery, sexual attention advances kind Trolling, insulting derogatory comments, personal political attacks Public private harassment Publishing others’ private information, physical email address, without explicit permission conduct reasonably considered inappropriate professional setting","code":""},{"path":"https://tidypredict.tidymodels.org/CODE_OF_CONDUCT.html","id":"enforcement-responsibilities","dir":"","previous_headings":"","what":"Enforcement Responsibilities","title":"Contributor Covenant Code of Conduct","text":"Community leaders responsible clarifying enforcing standards acceptable behavior take appropriate fair corrective action response behavior deem inappropriate, threatening, offensive, harmful. Community leaders right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct, communicate reasons moderation decisions appropriate.","code":""},{"path":"https://tidypredict.tidymodels.org/CODE_OF_CONDUCT.html","id":"scope","dir":"","previous_headings":"","what":"Scope","title":"Contributor Covenant Code of Conduct","text":"Code Conduct applies within community spaces, also applies individual officially representing community public spaces. Examples representing community include using official e-mail address, posting via official social media account, acting appointed representative online offline event.","code":""},{"path":"https://tidypredict.tidymodels.org/CODE_OF_CONDUCT.html","id":"enforcement","dir":"","previous_headings":"","what":"Enforcement","title":"Contributor Covenant Code of Conduct","text":"Instances abusive, harassing, otherwise unacceptable behavior may reported community leaders responsible enforcement [INSERT CONTACT METHOD]. complaints reviewed investigated promptly fairly. community leaders obligated respect privacy security reporter incident.","code":""},{"path":"https://tidypredict.tidymodels.org/CODE_OF_CONDUCT.html","id":"enforcement-guidelines","dir":"","previous_headings":"","what":"Enforcement Guidelines","title":"Contributor Covenant Code of Conduct","text":"Community leaders follow Community Impact Guidelines determining consequences action deem violation Code Conduct:","code":""},{"path":"https://tidypredict.tidymodels.org/CODE_OF_CONDUCT.html","id":"id_1-correction","dir":"","previous_headings":"Enforcement Guidelines","what":"1. Correction","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Use inappropriate language behavior deemed unprofessional unwelcome community. Consequence: private, written warning community leaders, providing clarity around nature violation explanation behavior inappropriate. public apology may requested.","code":""},{"path":"https://tidypredict.tidymodels.org/CODE_OF_CONDUCT.html","id":"id_2-warning","dir":"","previous_headings":"Enforcement Guidelines","what":"2. Warning","title":"Contributor Covenant Code of Conduct","text":"Community Impact: violation single incident series actions. Consequence: warning consequences continued behavior. interaction people involved, including unsolicited interaction enforcing Code Conduct, specified period time. includes avoiding interactions community spaces well external channels like social media. Violating terms may lead temporary permanent ban.","code":""},{"path":"https://tidypredict.tidymodels.org/CODE_OF_CONDUCT.html","id":"id_3-temporary-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"3. Temporary Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: serious violation community standards, including sustained inappropriate behavior. Consequence: temporary ban sort interaction public communication community specified period time. public private interaction people involved, including unsolicited interaction enforcing Code Conduct, allowed period. Violating terms may lead permanent ban.","code":""},{"path":"https://tidypredict.tidymodels.org/CODE_OF_CONDUCT.html","id":"id_4-permanent-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"4. Permanent Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Demonstrating pattern violation community standards, including sustained inappropriate behavior, harassment individual, aggression toward disparagement classes individuals. Consequence: permanent ban sort public interaction within community.","code":""},{"path":"https://tidypredict.tidymodels.org/CODE_OF_CONDUCT.html","id":"attribution","dir":"","previous_headings":"","what":"Attribution","title":"Contributor Covenant Code of Conduct","text":"Code Conduct adapted Contributor Covenant, version 2.0, available https://www.contributor-covenant.org/version/2/0/ code_of_conduct.html. Community Impact Guidelines inspired Mozilla’s code conduct enforcement ladder. answers common questions code conduct, see FAQ https://www.contributor-covenant.org/faq. Translations available https:// www.contributor-covenant.org/translations.","code":""},{"path":"https://tidypredict.tidymodels.org/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2021 tidypredict authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"https://tidypredict.tidymodels.org/articles/cubist.html","id":"tidypredict_-functions","dir":"Articles","previous_headings":"","what":"tidypredict_ functions","title":"Cubist models","text":"Create R formula SQL output example Add prediction original table Confirm tidypredict results match model’s predict() results","code":"library(Cubist) data(\"BostonHousing\", package = \"mlbench\") model <- Cubist::cubist(x = BostonHousing[, -14], y = BostonHousing$medv, committees = 3) tidypredict_fit(model) #> (ifelse(nox >= 0.668, -1.11 + crim * -0.02 + nox * 21.4 + rm * #> 0.1 + age * -0.003 + dis * 2.93 + ptratio * -0.13 + b * 0.008 + #> lstat * -0.33, 0) + ifelse(lstat >= 9.59 & nox < 0.668, 23.57 + #> crim * 0.05 + nox * -5.2 + rm * 3.1 + age * -0.048 + dis * #> -0.81 + rad * 0.02 + tax * -0.0041 + ptratio * -0.71 + b * #> 0.01 + lstat * -0.15, 0) + ifelse(lstat < 9.59 & rm < 6.226, #> 1.18 + crim * 3.83 + rm * 4.3 + age * -0.06 + dis * -0.09 + #> tax * -0.003 + ptratio * -0.08 + lstat * -0.11, 0) + #> ifelse(lstat < 9.59 & rm >= 6.226, -4.71 + crim * 2.22 + #> zn * 0.008 + nox * -1.7 + rm * 9.2 + age * -0.04 + dis * #> -0.71 + rad * 0.03 + tax * -0.0182 + ptratio * -0.72 + #> lstat * -0.83, 0) + ifelse(dis < 1.755 & lstat >= 5.12, #> 122.32 + crim * -0.29 + nox * -21.6 + rm * -3 + dis * -30.88 + #> rad * 0.02 + tax * -0.001 + b * -0.023 + lstat * -0.73, #> 0) + ifelse(rm < 6.545 & lstat >= 5.12, 27.8 + crim * -0.16 + #> zn * 0.007 + nox * -3.9 + rm * 2 + age * -0.035 + dis * -0.7 + #> rad * 0.28 + tax * -0.0135 + ptratio * -0.6 + b * 0.013 + #> lstat * -0.25, 0) + ifelse(rm >= 6.545 & lstat >= 5.12, 22.21 + #> crim * -0.04 + zn * 0.01 + indus * -0.02 + nox * -4 + rm * #> 4.7 + dis * -0.34 + rad * 0.11 + tax * -0.0248 + ptratio * #> -0.9 + b * 0.002 + lstat * -0.1, 0) + ifelse(lstat < 5.12 & #> rm < 8.034, -71.95 + rm * 17 + age * -0.06 + tax * -0.0112 + #> ptratio * -0.48 + lstat * -0.03, 0) + ifelse(rm >= 8.034 & #> dis >= 3.199, -32.79 + crim * -0.01 + zn * 0.005 + nox * #> -1.8 + rm * 12.9 + age * -0.117 + dis * -0.15 + rad * 0.04 + #> tax * -0.0246 + ptratio * -1.05 + lstat * -0.04, 0) + ifelse(lstat < #> 5.12 & dis < 3.199, 53.41 + rm * 1.6 + dis * -7.16 + tax * #> 0.0088 + lstat * -0.68, 0) + ifelse(nox >= 0.668, -36.31 + #> crim * 0.08 + nox * 48.4 + dis * 7.52 + b * 0.01 + lstat * #> -0.24, 0) + ifelse(lstat >= 9.53 & nox < 0.668, 28.04 + nox * #> -4.8 + rm * 2.9 + age * -0.051 + dis * -0.86 + rad * 0.01 + #> tax * -0.0019 + ptratio * -0.72 + lstat * -0.12, 0) + ifelse(lstat < #> 9.53, -26.05 + crim * 0.89 + nox * -2.3 + rm * 9.6 + dis * #> -0.17 + rad * 0.02 + tax * -0.0055 + ptratio * -0.12 + b * #> 0.001 + lstat * -0.74, 0) + ifelse(lstat < 9.53 & dis < 2.64, #> 136.67 + crim * 7.2 + nox * -96.6 + rm * 1.1 + tax * -0.0033 + #> ptratio * -3.31 + lstat * -0.1, 0))/3 tidypredict_sql(model, dbplyr::simulate_odbc()) #> <SQL> (((((((((((((CASE WHEN (`nox` >= 0.668) THEN ((((((((-1.11 + `crim` * -0.02) + `nox` * 21.4) + `rm` * 0.1) + `age` * -0.003) + `dis` * 2.93) + `ptratio` * -0.13) + `b` * 0.008) + `lstat` * -0.33) WHEN NOT (`nox` >= 0.668) THEN 0.0 END + CASE WHEN (`lstat` >= 9.59 AND `nox` < 0.668) THEN ((((((((((23.57 + `crim` * 0.05) + `nox` * -5.2) + `rm` * 3.1) + `age` * -0.048) + `dis` * -0.81) + `rad` * 0.02) + `tax` * -0.0041) + `ptratio` * -0.71) + `b` * 0.01) + `lstat` * -0.15) WHEN NOT (`lstat` >= 9.59 AND `nox` < 0.668) THEN 0.0 END) + CASE WHEN (`lstat` < 9.59 AND `rm` < 6.226) THEN (((((((1.18 + `crim` * 3.83) + `rm` * 4.3) + `age` * -0.06) + `dis` * -0.09) + `tax` * -0.003) + `ptratio` * -0.08) + `lstat` * -0.11) WHEN NOT (`lstat` < 9.59 AND `rm` < 6.226) THEN 0.0 END) + CASE WHEN (`lstat` < 9.59 AND `rm` >= 6.226) THEN ((((((((((-4.71 + `crim` * 2.22) + `zn` * 0.008) + `nox` * -1.7) + `rm` * 9.2) + `age` * -0.04) + `dis` * -0.71) + `rad` * 0.03) + `tax` * -0.0182) + `ptratio` * -0.72) + `lstat` * -0.83) WHEN NOT (`lstat` < 9.59 AND `rm` >= 6.226) THEN 0.0 END) + CASE WHEN (`dis` < 1.755 AND `lstat` >= 5.12) THEN ((((((((122.32 + `crim` * -0.29) + `nox` * -21.6) + `rm` * -3.0) + `dis` * -30.88) + `rad` * 0.02) + `tax` * -0.001) + `b` * -0.023) + `lstat` * -0.73) WHEN NOT (`dis` < 1.755 AND `lstat` >= 5.12) THEN 0.0 END) + CASE WHEN (`rm` < 6.545 AND `lstat` >= 5.12) THEN (((((((((((27.8 + `crim` * -0.16) + `zn` * 0.007) + `nox` * -3.9) + `rm` * 2.0) + `age` * -0.035) + `dis` * -0.7) + `rad` * 0.28) + `tax` * -0.0135) + `ptratio` * -0.6) + `b` * 0.013) + `lstat` * -0.25) WHEN NOT (`rm` < 6.545 AND `lstat` >= 5.12) THEN 0.0 END) + CASE WHEN (`rm` >= 6.545 AND `lstat` >= 5.12) THEN (((((((((((22.21 + `crim` * -0.04) + `zn` * 0.01) + `indus` * -0.02) + `nox` * -4.0) + `rm` * 4.7) + `dis` * -0.34) + `rad` * 0.11) + `tax` * -0.0248) + `ptratio` * -0.9) + `b` * 0.002) + `lstat` * -0.1) WHEN NOT (`rm` >= 6.545 AND `lstat` >= 5.12) THEN 0.0 END) + CASE WHEN (`lstat` < 5.12 AND `rm` < 8.034) THEN (((((-71.95 + `rm` * 17.0) + `age` * -0.06) + `tax` * -0.0112) + `ptratio` * -0.48) + `lstat` * -0.03) WHEN NOT (`lstat` < 5.12 AND `rm` < 8.034) THEN 0.0 END) + CASE WHEN (`rm` >= 8.034 AND `dis` >= 3.199) THEN ((((((((((-32.79 + `crim` * -0.01) + `zn` * 0.005) + `nox` * -1.8) + `rm` * 12.9) + `age` * -0.117) + `dis` * -0.15) + `rad` * 0.04) + `tax` * -0.0246) + `ptratio` * -1.05) + `lstat` * -0.04) WHEN NOT (`rm` >= 8.034 AND `dis` >= 3.199) THEN 0.0 END) + CASE WHEN (`lstat` < 5.12 AND `dis` < 3.199) THEN ((((53.41 + `rm` * 1.6) + `dis` * -7.16) + `tax` * 0.0088) + `lstat` * -0.68) WHEN NOT (`lstat` < 5.12 AND `dis` < 3.199) THEN 0.0 END) + CASE WHEN (`nox` >= 0.668) THEN (((((-36.31 + `crim` * 0.08) + `nox` * 48.4) + `dis` * 7.52) + `b` * 0.01) + `lstat` * -0.24) WHEN NOT (`nox` >= 0.668) THEN 0.0 END) + CASE WHEN (`lstat` >= 9.53 AND `nox` < 0.668) THEN ((((((((28.04 + `nox` * -4.8) + `rm` * 2.9) + `age` * -0.051) + `dis` * -0.86) + `rad` * 0.01) + `tax` * -0.0019) + `ptratio` * -0.72) + `lstat` * -0.12) WHEN NOT (`lstat` >= 9.53 AND `nox` < 0.668) THEN 0.0 END) + CASE WHEN (`lstat` < 9.53) THEN (((((((((-26.05 + `crim` * 0.89) + `nox` * -2.3) + `rm` * 9.6) + `dis` * -0.17) + `rad` * 0.02) + `tax` * -0.0055) + `ptratio` * -0.12) + `b` * 0.001) + `lstat` * -0.74) WHEN NOT (`lstat` < 9.53) THEN 0.0 END) + CASE WHEN (`lstat` < 9.53 AND `dis` < 2.64) THEN ((((((136.67 + `crim` * 7.2) + `nox` * -96.6) + `rm` * 1.1) + `tax` * -0.0033) + `ptratio` * -3.31) + `lstat` * -0.1) WHEN NOT (`lstat` < 9.53 AND `dis` < 2.64) THEN 0.0 END) / 3.0 library(dplyr) BostonHousing %>% tidypredict_to_column(model) %>% glimpse() #> Rows: 506 #> Columns: 15 #> $ crim <dbl> 0.00632, 0.02731, 0.02729, 0.03237, 0.06905, 0.02985, 0.… #> $ zn <dbl> 18.0, 0.0, 0.0, 0.0, 0.0, 0.0, 12.5, 12.5, 12.5, 12.5, 1… #> $ indus <dbl> 2.31, 7.07, 7.07, 2.18, 2.18, 2.18, 7.87, 7.87, 7.87, 7.… #> $ chas <fct> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,… #> $ nox <dbl> 0.538, 0.469, 0.469, 0.458, 0.458, 0.458, 0.524, 0.524, … #> $ rm <dbl> 6.575, 6.421, 7.185, 6.998, 7.147, 6.430, 6.012, 6.172, … #> $ age <dbl> 65.2, 78.9, 61.1, 45.8, 54.2, 58.7, 66.6, 96.1, 100.0, 8… #> $ dis <dbl> 4.0900, 4.9671, 4.9671, 6.0622, 6.0622, 6.0622, 5.5605, … #> $ rad <dbl> 1, 2, 2, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4,… #> $ tax <dbl> 296, 242, 242, 222, 222, 222, 311, 311, 311, 311, 311, 3… #> $ ptratio <dbl> 15.3, 17.8, 17.8, 18.7, 18.7, 18.7, 15.2, 15.2, 15.2, 15… #> $ b <dbl> 396.90, 396.90, 392.83, 394.63, 396.90, 394.12, 395.60, … #> $ lstat <dbl> 4.98, 9.14, 4.03, 2.94, 5.33, 5.21, 12.43, 19.15, 29.93,… #> $ medv <dbl> 24.0, 21.6, 34.7, 33.4, 36.2, 28.7, 22.9, 27.1, 16.5, 18… #> $ fit <dbl> 27.50665, 22.71805, 34.78128, 33.19372, 31.93653, 25.037… tidypredict_test(model, BostonHousing) #> tidypredict test results #> Difference threshold: 1e-12 #> #> Fitted records above the threshold: 506 #> #> Fit max difference: #> Lower max difference: #> Upper max difference:2.62966510913086"},{"path":"https://tidypredict.tidymodels.org/articles/cubist.html","id":"parse-model-spec","dir":"Articles","previous_headings":"","what":"Parse model spec","title":"Cubist models","text":"example model spec:","code":"pm <- parse_model(model) str(pm, 2) #> List of 2 #> $ general:List of 5 #> ..$ model : chr \"cubist\" #> ..$ type : chr \"tree\" #> ..$ version: num 2 #> ..$ mode : chr \"ifelse\" #> ..$ divisor: num 3 #> $ trees :List of 1 #> ..$ :List of 14 #> - attr(*, \"class\")= chr [1:3] \"parsed_model\" \"pm_tree\" \"list\" str(pm$terms[1:2]) #> NULL"},{"path":"https://tidypredict.tidymodels.org/articles/glm.html","id":"highlights-limitations","dir":"Articles","previous_headings":"","what":"Highlights & Limitations","title":"Generalized Linear Regression","text":"Defaults 0--1 predictions binomial family models. akin running predict(model, type = \"response\") treatment contrast (contr.treatment) supported. offset supported Categorical variables supported OK - wt ~ mpg + OK - mutate(mtcars, newam = paste0()) wt ~ mpg + newam OK - wt ~ mpg + .factor() OK - wt ~ mpg + .character() Interval functions supported: tidypredict_interval() & tidypredict_sql_interval()","code":""},{"path":"https://tidypredict.tidymodels.org/articles/glm.html","id":"how-it-works","dir":"Articles","previous_headings":"","what":"How it works","title":"Generalized Linear Regression","text":"returns SQL query contains coefficients (model$coefficients) operated correct variable categorical variable value. cases resulting SQL one short CASE statement per coefficient. appends offset field value, one provided. binomial models, sigmoid equation applied. means target SQL database type need support exponent function. Alternatively, use tidypredict_to_column() results used previewed dplyr.","code":"library(tidypredict) library(dplyr) df <- mtcars %>% mutate(char_cyl = paste0(\"cyl\", cyl)) %>% select(wt, char_cyl, am) model <- glm(am ~ wt + char_cyl, data = df, family = \"binomial\") library(tidypredict) tidypredict_sql(model, dbplyr::simulate_mssql()) #> <SQL> 1.0 - 1.0 / (1.0 + EXP(((20.8527831345691 + (`wt` * -7.85934263583836)) + (IIF(`char_cyl` = 'cyl6', 1.0, 0.0) * 3.10462643177453)) + (IIF(`char_cyl` = 'cyl8', 1.0, 0.0) * 5.37942092366097))) df %>% tidypredict_to_column(model) %>% head(10) #> wt char_cyl am fit #> Mazda RX4 2.620 cyl6 1 0.96662269 #> Mazda RX4 Wag 2.875 cyl6 1 0.79605201 #> Datsun 710 2.320 cyl4 1 0.93208127 #> Hornet 4 Drive 3.215 cyl6 0 0.21242376 #> Hornet Sportabout 3.440 cyl8 0 0.30918450 #> Valiant 3.460 cyl6 0 0.03783629 #> Duster 360 3.570 cyl8 0 0.13875740 #> Merc 240D 3.190 cyl4 0 0.01450687 #> Merc 230 3.150 cyl4 0 0.01975984 #> Merc 280 3.440 cyl6 0 0.04399324"},{"path":"https://tidypredict.tidymodels.org/articles/glm.html","id":"under-the-hood","dir":"Articles","previous_headings":"","what":"Under the hood","title":"Generalized Linear Regression","text":"parser reads several parts glm object tabulate needed variables. One entry per coefficient added final table. variables added end. variables required every parsed model. example, offset listed ’s part formula (call) model, offset given model, line exist. output parse_model() transformed dplyr, .k.Tidy Eval, formula. categorical variables operated using if_else(). , Tidy Eval formula can used anywhere can operated. tidypredict provides three paths: Use directly inside dplyr, mutate(df, !! tidypredict_fit(model)) Use tidypredict_to_column(model) piped command set Use tidypredict_to_sql(model) retrieve SQL statement applies prediction interval functions.","code":"pm <- parse_model(model) str(pm, 2) #> List of 2 #> $ general:List of 7 #> ..$ model : chr \"glm\" #> ..$ version : num 2 #> ..$ type : chr \"regression\" #> ..$ residual: int 28 #> ..$ family : chr \"binomial\" #> ..$ link : chr \"logit\" #> ..$ is_glm : num 1 #> $ terms :List of 4 #> ..$ :List of 5 #> ..$ :List of 5 #> ..$ :List of 5 #> ..$ :List of 5 #> - attr(*, \"class\")= chr [1:3] \"parsed_model\" \"pm_regression\" \"list\" tidypredict_fit(model) #> 1 - 1/(1 + exp(20.8527831345691 + (wt * -7.85934263583836) + #> (ifelse(char_cyl == \"cyl6\", 1, 0) * 3.10462643177453) + (ifelse(char_cyl == #> \"cyl8\", 1, 0) * 5.37942092366097)))"},{"path":"https://tidypredict.tidymodels.org/articles/glm.html","id":"how-it-performs","dir":"Articles","previous_headings":"","what":"How it performs","title":"Generalized Linear Regression","text":"Testing tidypredict results easy. tidypredict_test() function automatically uses lm model object’s data frame, compare tidypredict_fit(), tidypredict_interval() results given predict()","code":"tidypredict_test(model) #> tidypredict test results #> Difference threshold: 1e-12 #> #> All results are within the difference threshold"},{"path":"https://tidypredict.tidymodels.org/articles/lm.html","id":"highlights-limitations","dir":"Articles","previous_headings":"","what":"Highlights & Limitations","title":"Linear Regression","text":"Supports prediction intervals, uses qr.solve() function parse interval coefficient term. Supports categorical variables interactions treatment contrast (contr.treatment) supported. offset supported Categorical variables supported OK - wt ~ mpg + OK - mutate(mtcars, newam = paste0()) wt ~ mpg + newam OK - wt ~ mpg + .factor() OK - wt ~ mpg + .character()","code":""},{"path":"https://tidypredict.tidymodels.org/articles/lm.html","id":"how-it-works","dir":"Articles","previous_headings":"","what":"How it works","title":"Linear Regression","text":"returns SQL query contains coefficients (model$coefficients) operated correct variable categorical variable value. cases resulting SQL one short CASE statement per coefficient. appends offset field value, one provided. Alternatively, use tidypredict_to_column() results used previewed dplyr.","code":"library(dplyr) library(tidypredict) df <- mtcars %>% mutate(char_cyl = paste0(\"cyl\", cyl)) %>% select(mpg, wt, char_cyl, am) model <- lm(mpg ~ wt + char_cyl, offset = am, data = df) library(tidypredict) tidypredict_sql(model, dbplyr::simulate_mssql()) #> <SQL> (((32.4105336886021 + (`wt` * -2.83243330448326)) + (IIF(`char_cyl` = 'cyl6', 1.0, 0.0) * -4.26714873091281)) + (IIF(`char_cyl` = 'cyl8', 1.0, 0.0) * -6.12588309683682)) + `am` df %>% tidypredict_to_column(model) %>% head(10) #> mpg wt char_cyl am fit #> Mazda RX4 21.0 2.620 cyl6 1 21.72241 #> Mazda RX4 Wag 21.0 2.875 cyl6 1 21.00014 #> Datsun 710 22.8 2.320 cyl4 1 26.83929 #> Hornet 4 Drive 21.4 3.215 cyl6 0 19.03711 #> Hornet Sportabout 18.7 3.440 cyl8 0 16.54108 #> Valiant 18.1 3.460 cyl6 0 18.34317 #> Duster 360 14.3 3.570 cyl8 0 16.17286 #> Merc 240D 24.4 3.190 cyl4 0 23.37507 #> Merc 230 22.8 3.150 cyl4 0 23.48837 #> Merc 280 19.2 3.440 cyl6 0 18.39981"},{"path":"https://tidypredict.tidymodels.org/articles/lm.html","id":"prediction-intervals","dir":"Articles","previous_headings":"","what":"Prediction intervals","title":"Linear Regression","text":"Use tidypredict_sql_interval() get SQL query operates prediction interval. interval defaults 0.95 Prediction intervals also works tidypredict_to_column(), just set add_interval argument TRUE.","code":"tidypredict_sql_interval(model, dbplyr::simulate_mssql()) #> <SQL> 2.04840714179524 * SQRT(((((((-0.176776695296637) * (-0.176776695296637)) * 6.63799055122669) + ((-0.590557271637747 + `wt` * 0.183559646169165) * (-0.590557271637747 + `wt` * 0.183559646169165)) * 6.63799055122669) + (((-0.126215672528828 + `wt` * 0.0101118696567173) + IIF(`char_cyl` = 'cyl6', 1.0, 0.0) * 0.428266330860589) * ((-0.126215672528828 + `wt` * 0.0101118696567173) + IIF(`char_cyl` = 'cyl6', 1.0, 0.0) * 0.428266330860589)) * 6.63799055122669) + ((((0.386215468111418 + `wt` * -0.230516217152034) + IIF(`char_cyl` = 'cyl6', 1.0, 0.0) * 0.332336511639638) + IIF(`char_cyl` = 'cyl8', 1.0, 0.0) * 0.646203930513815) * (((0.386215468111418 + `wt` * -0.230516217152034) + IIF(`char_cyl` = 'cyl6', 1.0, 0.0) * 0.332336511639638) + IIF(`char_cyl` = 'cyl8', 1.0, 0.0) * 0.646203930513815)) * 6.63799055122669) + 6.63799055122669) df %>% tidypredict_to_column(model, add_interval = TRUE) %>% head(10) #> mpg wt char_cyl am fit upper lower #> Mazda RX4 21.0 2.620 cyl6 1 21.72241 27.41716 16.02765 #> Mazda RX4 Wag 21.0 2.875 cyl6 1 21.00014 26.65467 15.34560 #> Datsun 710 22.8 2.320 cyl4 1 26.83929 32.35180 21.32678 #> Hornet 4 Drive 21.4 3.215 cyl6 0 19.03711 24.68113 13.39309 #> Hornet Sportabout 18.7 3.440 cyl8 0 16.54108 22.07276 11.00940 #> Valiant 18.1 3.460 cyl6 0 18.34317 24.01030 12.67603 #> Duster 360 14.3 3.570 cyl8 0 16.17286 21.67635 10.66938 #> Merc 240D 24.4 3.190 cyl4 0 23.37507 29.06408 17.68606 #> Merc 230 22.8 3.150 cyl4 0 23.48837 29.16231 17.81443 #> Merc 280 19.2 3.440 cyl6 0 18.39981 24.06411 12.73552"},{"path":"https://tidypredict.tidymodels.org/articles/lm.html","id":"under-the-hood","dir":"Articles","previous_headings":"","what":"Under the hood","title":"Linear Regression","text":"parser reads several parts lm object tabulate needed variables. One entry per coefficient added final table, entries results qr.solve() already operated placed correct column, qr_ prefix. one qr_ column per coefficient. variables added end. variables required every parsed model. example, offset listed ’s part formula (call) model, offset given model, line exist. output parse_model() transformed dplyr, .k.Tidy Eval, formula. categorical variables operated using if_else(). function put together Tidy Eval interval formula also supported , Tidy Eval formula can used anywhere can operated. tidypredict provides three paths: Use directly inside dplyr, mutate(df, !! tidypredict_fit(model)) Use tidypredict_to_column(model) piped command set Use tidypredict_to_sql(model) retrieve SQL statement applies prediction interval functions.","code":"pm <- parse_model(model) str(pm, 2) #> List of 2 #> $ general:List of 7 #> ..$ model : chr \"lm\" #> ..$ version : num 2 #> ..$ type : chr \"regression\" #> ..$ residual: int 28 #> ..$ sigma2 : num 6.64 #> ..$ offset : symbol am #> ..$ is_glm : num 0 #> $ terms :List of 4 #> ..$ :List of 5 #> ..$ :List of 5 #> ..$ :List of 5 #> ..$ :List of 5 #> - attr(*, \"class\")= chr [1:3] \"parsed_model\" \"pm_regression\" \"list\" tidypredict_fit(model) #> 32.4105336886021 + (wt * -2.83243330448326) + (ifelse(char_cyl == #> \"cyl6\", 1, 0) * -4.26714873091281) + (ifelse(char_cyl == #> \"cyl8\", 1, 0) * -6.12588309683682) + am tidypredict_interval(model) #> 2.04840714179524 * sqrt((-0.176776695296637) * (-0.176776695296637) * #> 6.63799055122669 + (-0.590557271637747 + wt * 0.183559646169165) * #> (-0.590557271637747 + wt * 0.183559646169165) * 6.63799055122669 + #> (-0.126215672528828 + wt * 0.0101118696567173 + ifelse(char_cyl == #> \"cyl6\", 1, 0) * 0.428266330860589) * (-0.126215672528828 + #> wt * 0.0101118696567173 + ifelse(char_cyl == \"cyl6\", #> 1, 0) * 0.428266330860589) * 6.63799055122669 + (0.386215468111418 + #> wt * -0.230516217152034 + ifelse(char_cyl == \"cyl6\", 1, 0) * #> 0.332336511639638 + ifelse(char_cyl == \"cyl8\", 1, 0) * 0.646203930513815) * #> (0.386215468111418 + wt * -0.230516217152034 + ifelse(char_cyl == #> \"cyl6\", 1, 0) * 0.332336511639638 + ifelse(char_cyl == #> \"cyl8\", 1, 0) * 0.646203930513815) * 6.63799055122669 + #> 6.63799055122669)"},{"path":"https://tidypredict.tidymodels.org/articles/lm.html","id":"how-it-performs","dir":"Articles","previous_headings":"","what":"How it performs","title":"Linear Regression","text":"Testing tidypredict results easy. tidypredict_test() function automatically uses lm model object’s data frame, compare tidypredict_fit(), tidypredict_interval() results given predict() run prediction intervals set include_intervals argument TRUE","code":"tidypredict_test(model) #> tidypredict test results #> Difference threshold: 1e-12 #> #> All results are within the difference threshold tidypredict_test(model, include_intervals = TRUE) #> tidypredict test results #> Difference threshold: 1e-12 #> #> All results are within the difference threshold"},{"path":"https://tidypredict.tidymodels.org/articles/lm.html","id":"parsnip","dir":"Articles","previous_headings":"","what":"parsnip","title":"Linear Regression","text":"tidypredict also supports lm() model objects fitted via parsnip package.","code":"library(parsnip) parsnip_model <- linear_reg() %>% set_engine(\"lm\") %>% fit(mpg ~ wt + cyl, offset = am, data = mtcars) tidypredict_fit(parsnip_model) #> 39.686261480253 + (wt * -3.19097213898375) + (cyl * -1.5077949682598)"},{"path":"https://tidypredict.tidymodels.org/articles/mars.html","id":"tidypredict_-functions","dir":"Articles","previous_headings":"","what":"tidypredict_ functions","title":"MARS models via the `earth` package","text":"Create R formula SQL output example Add prediction original table Confirm tidypredict results match model’s predict() results","code":"library(earth) data(\"etitanic\", package = \"earth\") model <- earth(age ~ sibsp + parch, data = etitanic, degree = 3) tidypredict_fit(model) #> 22.2918960405404 + (ifelse(parch < 2, 2 - parch, 0) * 4.85356462114363) + #> (ifelse(parch > 2, parch - 2, 0) * 13.0493891423278) + (ifelse(parch > #> 4, parch - 4, 0) * -18.8998708031821) + (ifelse(sibsp > 1, #> sibsp - 1, 0) * -7.71566779782019) + (ifelse(sibsp > 1, sibsp - #> 1, 0) * ifelse(parch < 1, 1 - parch, 0) * 7.40395975552276) + #> (ifelse(sibsp > 1, sibsp - 1, 0) * ifelse(parch > 1, parch - #> 1, 0) * 4.41874354843216) tidypredict_sql(model, dbplyr::simulate_odbc()) #> <SQL> (((((22.2918960405404 + (CASE WHEN (`parch` < 2.0) THEN (2.0 - `parch`) WHEN NOT (`parch` < 2.0) THEN 0.0 END * 4.85356462114363)) + (CASE WHEN (`parch` > 2.0) THEN (`parch` - 2.0) WHEN NOT (`parch` > 2.0) THEN 0.0 END * 13.0493891423278)) + (CASE WHEN (`parch` > 4.0) THEN (`parch` - 4.0) WHEN NOT (`parch` > 4.0) THEN 0.0 END * -18.8998708031821)) + (CASE WHEN (`sibsp` > 1.0) THEN (`sibsp` - 1.0) WHEN NOT (`sibsp` > 1.0) THEN 0.0 END * -7.71566779782019)) + ((CASE WHEN (`sibsp` > 1.0) THEN (`sibsp` - 1.0) WHEN NOT (`sibsp` > 1.0) THEN 0.0 END * CASE WHEN (`parch` < 1.0) THEN (1.0 - `parch`) WHEN NOT (`parch` < 1.0) THEN 0.0 END) * 7.40395975552276)) + ((CASE WHEN (`sibsp` > 1.0) THEN (`sibsp` - 1.0) WHEN NOT (`sibsp` > 1.0) THEN 0.0 END * CASE WHEN (`parch` > 1.0) THEN (`parch` - 1.0) WHEN NOT (`parch` > 1.0) THEN 0.0 END) * 4.41874354843216) library(dplyr) etitanic %>% tidypredict_to_column(model) %>% glimpse() #> Rows: 1,046 #> Columns: 7 #> $ pclass <fct> 1st, 1st, 1st, 1st, 1st, 1st, 1st, 1st, 1st, 1st, 1st, … #> $ survived <int> 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0… #> $ sex <fct> female, male, female, male, female, male, female, male,… #> $ age <dbl> 29.0000, 0.9167, 2.0000, 30.0000, 25.0000, 48.0000, 63.… #> $ sibsp <int> 0, 1, 1, 1, 1, 0, 1, 0, 2, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0… #> $ parch <int> 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0… #> $ fit <dbl> 31.99903, 22.29190, 22.29190, 22.29190, 22.29190, 31.99… tidypredict_test(model, etitanic) #> tidypredict test results #> Difference threshold: 1e-12 #> #> All results are within the difference threshold"},{"path":"https://tidypredict.tidymodels.org/articles/mars.html","id":"glm-models","dir":"Articles","previous_headings":"","what":"GLM models","title":"MARS models via the `earth` package","text":"tidypredict supports glm argument well: spec sets is_glm entry 1, well family link entries.","code":"model <- earth(survived ~ ., data = etitanic, glm = list(family = binomial), degree = 2 ) tidypredict_fit(model) #> 1 - 1/(1 + exp(2.91352600741336 + (ifelse(age > 32, age - 32, #> 0) * -0.0375714917713104) + (ifelse(pclass == \"2nd\", 1, 0) * #> ifelse(sex == \"male\", 1, 0) * -1.76809447811121) + (ifelse(pclass == #> \"3rd\", 1, 0) * -5.03005595780694) + (ifelse(pclass == \"3rd\", #> 1, 0) * ifelse(sibsp < 4, 4 - sibsp, 0) * 0.618652747659846) + #> (ifelse(pclass == \"3rd\", 1, 0) * ifelse(sex == \"male\", 1, #> 0) * 1.22269536265148) + (ifelse(sex == \"male\", 1, 0) * #> -3.18562450248531) + (ifelse(sex == \"male\", 1, 0) * ifelse(age < #> 16, 16 - age, 0) * 0.241814028713263))) str(parse_model(model), 2) #> List of 2 #> $ general:List of 6 #> ..$ model : chr \"earth\" #> ..$ type : chr \"regression\" #> ..$ version: num 2 #> ..$ is_glm : num 1 #> ..$ family : chr \"binomial\" #> ..$ link : chr \"logit\" #> $ terms :List of 8 #> ..$ :List of 4 #> ..$ :List of 4 #> ..$ :List of 4 #> ..$ :List of 4 #> ..$ :List of 4 #> ..$ :List of 4 #> ..$ :List of 4 #> ..$ :List of 4 #> - attr(*, \"class\")= chr [1:3] \"parsed_model\" \"pm_regression\" \"list\""},{"path":"https://tidypredict.tidymodels.org/articles/mars.html","id":"parsnip","dir":"Articles","previous_headings":"","what":"parsnip","title":"MARS models via the `earth` package","text":"parsnip fitted models also supported tidypredict:","code":"library(parsnip) p_model <- mars(mode = \"regression\", prod_degree = 3) %>% set_engine(\"earth\") %>% fit(age ~ sibsp + parch, data = etitanic) tidypredict_fit(p_model) #> 22.2918960405404 + (ifelse(parch < 2, 2 - parch, 0) * 4.85356462114363) + #> (ifelse(parch > 2, parch - 2, 0) * 13.0493891423278) + (ifelse(parch > #> 4, parch - 4, 0) * -18.8998708031821) + (ifelse(sibsp > 1, #> sibsp - 1, 0) * -7.71566779782019) + (ifelse(sibsp > 1, sibsp - #> 1, 0) * ifelse(parch < 1, 1 - parch, 0) * 7.40395975552276) + #> (ifelse(sibsp > 1, sibsp - 1, 0) * ifelse(parch > 1, parch - #> 1, 0) * 4.41874354843216)"},{"path":"https://tidypredict.tidymodels.org/articles/mars.html","id":"parse-model-spec","dir":"Articles","previous_headings":"","what":"Parse model spec","title":"MARS models via the `earth` package","text":"example model spec:","code":"pm <- parse_model(model) str(pm, 2) #> List of 2 #> $ general:List of 6 #> ..$ model : chr \"earth\" #> ..$ type : chr \"regression\" #> ..$ version: num 2 #> ..$ is_glm : num 1 #> ..$ family : chr \"binomial\" #> ..$ link : chr \"logit\" #> $ terms :List of 8 #> ..$ :List of 4 #> ..$ :List of 4 #> ..$ :List of 4 #> ..$ :List of 4 #> ..$ :List of 4 #> ..$ :List of 4 #> ..$ :List of 4 #> ..$ :List of 4 #> - attr(*, \"class\")= chr [1:3] \"parsed_model\" \"pm_regression\" \"list\" str(pm$terms[1:2]) #> List of 2 #> $ :List of 4 #> ..$ label : chr \"(Intercept)\" #> ..$ coef : num 2.91 #> ..$ is_intercept: num 1 #> ..$ fields :List of 1 #> .. ..$ : list() #> $ :List of 4 #> ..$ label : chr \"h(age-32)\" #> ..$ coef : num -0.0376 #> ..$ is_intercept: num 0 #> ..$ fields :List of 1 #> .. ..$ :List of 4 #> .. .. ..$ type: chr \"operation\" #> .. .. ..$ col : chr \"age\" #> .. .. ..$ val : num 32 #> .. .. ..$ op : chr \"morethan\""},{"path":"https://tidypredict.tidymodels.org/articles/non-r.html","id":"python-example","dir":"Articles","previous_headings":"","what":"python example","title":"Non-R Models","text":"model fitted using sklearn’s linear_model. model based diabetes data. Ten baseline variables, age, sex, body mass index, average blood pressure, six blood serum measurements obtained n = 442 diabetes patients, well response interest, quantitative measure disease progression one year baseline. model’s results converted YAML python script, copied pasted top part :","code":"general: is_glm: 0 model: lm residual: 0 sigma2: 0 type: regression version: 2.0 terms: - coef: 152.76430691633442 fields: - col: (Intercept) type: ordinary is_intercept: 1 label: (Intercept)"},{"path":"https://tidypredict.tidymodels.org/articles/non-r.html","id":"read-in-r","dir":"Articles","previous_headings":"","what":"Read in R","title":"Non-R Models","text":"YAML data can read R using yaml package. example, copy-pasted models inside variable called sklearn_model. yaml requires local YAML variables split line, use strsplit(). Now model converted R list using yaml.load.","code":"library(yaml) sklearn_model <- strsplit(\"general: is_glm: 0 model: lm residual: 0 sigma2: 0 type: regression version: 2.0 terms: - coef: 152.76430691633442 fields: - col: (Intercept) type: ordinary is_intercept: 1 label: (Intercept) - coef: 0.3034995490660432 fields: - col: age type: ordinary is_intercept: 0 label: age - coef: -237.63931533353403 fields: - col: sex type: ordinary is_intercept: 0 label: sex - coef: 510.5306054362253 fields: - col: bmi type: ordinary is_intercept: 0 label: bmi - coef: 327.7369804093466 fields: - col: bp type: ordinary is_intercept: 0 label: bp - coef: -814.1317093725387 fields: - col: s1 type: ordinary is_intercept: 0 label: s1 \", split = \"\\n\")[[1]] sklearn_model <- yaml.load(sklearn_model) str(sklearn_model, 2) #> List of 2 #> $ general:List of 6 #> ..$ is_glm : int 0 #> ..$ model : chr \"lm\" #> ..$ residual: int 0 #> ..$ sigma2 : int 0 #> ..$ type : chr \"regression\" #> ..$ version : num 2 #> $ terms :List of 6 #> ..$ :List of 4 #> ..$ :List of 4 #> ..$ :List of 4 #> ..$ :List of 4 #> ..$ :List of 4 #> ..$ :List of 4"},{"path":"https://tidypredict.tidymodels.org/articles/non-r.html","id":"tidypredict","dir":"Articles","previous_headings":"","what":"tidypredict","title":"Non-R Models","text":"list object needs recognized tidypredict parsed model. , use as_parsed_model() spm variable now works just parsed model inside R. Use tidypredict_fit() view resulting formula. Now, model can run inside database","code":"library(tidypredict) #> Error in get(paste0(generic, \".\", class), envir = get_method_env()) : #> object 'type_sum.accel' not found spm <- as_parsed_model(sklearn_model) class(spm) #> [1] \"parsed_model\" \"pm_regression\" \"list\" tidypredict_fit(spm) #> 152.764306916334 + (age * 0.303499549066043) + (sex * -237.639315333534) + #> (bmi * 510.530605436225) + (bp * 327.736980409347) + (s1 * #> -814.131709372539) tidypredict_sql(spm, dbplyr::simulate_mssql()) #> <SQL> ((((152.764306916334 + (`age` * 0.303499549066043)) + (`sex` * -237.639315333534)) + (`bmi` * 510.530605436225)) + (`bp` * 327.736980409347)) + (`s1` * -814.131709372539)"},{"path":"https://tidypredict.tidymodels.org/articles/non-r.html","id":"broom","dir":"Articles","previous_headings":"","what":"broom","title":"Non-R Models","text":"Now parsed_model object, possible use broom’s tidy() function. means able integrate totally external model, broom.","code":"tidy(spm) #> # A tibble: 6 × 2 #> term estimate #> <chr> <dbl> #> 1 (Intercept) 153. #> 2 age 0.303 #> 3 sex -238. #> 4 bmi 511. #> 5 bp 328. #> 6 s1 -814."},{"path":"https://tidypredict.tidymodels.org/articles/ranger.html","id":"how-it-works","dir":"Articles","previous_headings":"","what":"How it works","title":"Random Forest, using Ranger","text":"simple ranger() model using iris dataset:","code":"library(dplyr) library(tidypredict) library(ranger) model <- ranger(Species ~ ., data = iris, num.trees = 100)"},{"path":"https://tidypredict.tidymodels.org/articles/ranger.html","id":"under-the-hood","dir":"Articles","previous_headings":"","what":"Under the hood","title":"Random Forest, using Ranger","text":"parser based output ranger::treeInfo() function. return many decision paths non-NA rows prediction field. output parse_model() transformed dplyr, .k.Tidy Eval, formula. entire decision tree becomes one dplyr::case_when() statement , Tidy Eval formula can used anywhere can operated. tidypredict provides three paths: Use directly inside dplyr, mutate(iris, !! tidypredict_fit(model)) Use tidypredict_to_column(model) piped command set Use tidypredict_to_sql(model) retrieve SQL statement","code":"treeInfo(model) %>% head() #> nodeID leftChild rightChild splitvarID splitvarName splitval terminal #> 1 0 1 2 3 Petal.Width 1.75 FALSE #> 2 1 3 4 2 Petal.Length 2.45 FALSE #> 3 2 5 6 2 Petal.Length 4.85 FALSE #> 4 3 NA NA NA <NA> NA TRUE #> 5 4 7 8 2 Petal.Length 5.40 FALSE #> 6 5 NA NA NA <NA> NA TRUE #> prediction #> 1 <NA> #> 2 <NA> #> 3 <NA> #> 4 setosa #> 5 <NA> #> 6 virginica tidypredict_fit(model)[1] #> [[1]] #> case_when(Petal.Length < 2.45 & Petal.Width < 1.75 ~ \"setosa\", #> Petal.Length < 4.85 & Petal.Width >= 1.75 ~ \"virginica\", #> Petal.Length >= 4.85 & Petal.Width >= 1.75 ~ \"virginica\", #> Petal.Length < 5.4 & Petal.Length >= 2.45 & Petal.Width < #> 1.75 ~ \"versicolor\", Petal.Length >= 5.4 & Petal.Length >= #> 2.45 & Petal.Width < 1.75 ~ \"virginica\")"},{"path":"https://tidypredict.tidymodels.org/articles/ranger.html","id":"parsnip","dir":"Articles","previous_headings":"","what":"parsnip","title":"Random Forest, using Ranger","text":"tidypredict also supports ranger model objects fitted via parsnip package.","code":"library(parsnip) parsnip_model <- rand_forest(mode = \"classification\") %>% set_engine(\"ranger\") %>% fit(Species ~ ., data = iris) tidypredict_fit(parsnip_model)[[1]] #> case_when(Petal.Width < 0.8 ~ \"setosa\", Petal.Length >= 5.05 & #> Petal.Width >= 0.8 ~ \"virginica\", Petal.Width < 1.65 & Petal.Length < #> 4.75 & Petal.Length < 5.05 & Petal.Width >= 0.8 ~ \"versicolor\", #> Petal.Width >= 1.65 & Petal.Length < 4.75 & Petal.Length < #> 5.05 & Petal.Width >= 0.8 ~ \"virginica\", Sepal.Length >= #> 6.5 & Petal.Length >= 4.75 & Petal.Length < 5.05 & Petal.Width >= #> 0.8 ~ \"versicolor\", Sepal.Width < 3.1 & Sepal.Length < #> 6.5 & Petal.Length >= 4.75 & Petal.Length < 5.05 & Petal.Width >= #> 0.8 ~ \"virginica\", Sepal.Width >= 3.1 & Sepal.Length < #> 6.5 & Petal.Length >= 4.75 & Petal.Length < 5.05 & Petal.Width >= #> 0.8 ~ \"versicolor\")"},{"path":"https://tidypredict.tidymodels.org/articles/rf.html","id":"how-it-works","dir":"Articles","previous_headings":"","what":"How it works","title":"Random Forest","text":"simple randomForest() model using iris dataset:","code":"library(dplyr) library(tidypredict) library(randomForest) model <- randomForest(Species ~ ., data = iris, ntree = 100, proximity = TRUE)"},{"path":"https://tidypredict.tidymodels.org/articles/rf.html","id":"under-the-hood","dir":"Articles","previous_headings":"","what":"Under the hood","title":"Random Forest","text":"parser based output randomForest::getTree() function. return many decision paths non-NA rows prediction field. output parse_model() transformed dplyr, .k.Tidy Eval, formula. entire decision tree becomes one dplyr::case_when() statement , Tidy Eval formula can used anywhere can operated. tidypredict provides three paths: Use directly inside dplyr, mutate(iris, !! tidypredict_fit(model)) Use tidypredict_to_column(model) piped command set Use tidypredict_to_sql(model) retrieve SQL statement","code":"getTree(model, labelVar = TRUE) %>% head() #> left daughter right daughter split var split point status prediction #> 1 2 3 Petal.Length 2.50 1 <NA> #> 2 0 0 <NA> 0.00 -1 setosa #> 3 4 5 Petal.Length 5.05 1 <NA> #> 4 6 7 Petal.Width 1.90 1 <NA> #> 5 0 0 <NA> 0.00 -1 virginica #> 6 8 9 Sepal.Length 4.95 1 <NA> tidypredict_fit(model)[1] #> [[1]] #> case_when(Petal.Length < 2.5 ~ \"setosa\", Petal.Length >= 5.05 & #> Petal.Length >= 2.5 ~ \"virginica\", Petal.Width >= 1.9 & Petal.Length < #> 5.05 & Petal.Length >= 2.5 ~ \"virginica\", Sepal.Length < #> 4.95 & Petal.Width < 1.9 & Petal.Length < 5.05 & Petal.Length >= #> 2.5 ~ \"virginica\", Petal.Width < 1.75 & Sepal.Length >= 4.95 & #> Petal.Width < 1.9 & Petal.Length < 5.05 & Petal.Length >= #> 2.5 ~ \"versicolor\", Sepal.Width < 3 & Petal.Width >= 1.75 & #> Sepal.Length >= 4.95 & Petal.Width < 1.9 & Petal.Length < #> 5.05 & Petal.Length >= 2.5 ~ \"virginica\", Sepal.Width >= #> 3 & Petal.Width >= 1.75 & Sepal.Length >= 4.95 & Petal.Width < #> 1.9 & Petal.Length < 5.05 & Petal.Length >= 2.5 ~ \"versicolor\")"},{"path":"https://tidypredict.tidymodels.org/articles/rf.html","id":"parsnip","dir":"Articles","previous_headings":"","what":"parsnip","title":"Random Forest","text":"tidypredict also supports randomForest model objects fitted via parsnip package.","code":"library(parsnip) parsnip_model <- rand_forest(mode = \"classification\") %>% set_engine(\"randomForest\") %>% fit(Species ~ ., data = iris) tidypredict_fit(parsnip_model)[[1]] #> case_when(Petal.Length < 2.45 & Sepal.Length < 5.45 ~ \"setosa\", #> Petal.Width < 1.6 & Petal.Length >= 2.45 & Sepal.Length < #> 5.45 ~ \"versicolor\", Petal.Width >= 1.6 & Petal.Length >= #> 2.45 & Sepal.Length < 5.45 ~ \"virginica\", Petal.Length >= #> 4.7 & Sepal.Length < 5.75 & Sepal.Length >= 5.45 ~ \"virginica\", #> Petal.Width < 0.65 & Petal.Length < 4.7 & Sepal.Length < #> 5.75 & Sepal.Length >= 5.45 ~ \"setosa\", Petal.Width >= #> 0.65 & Petal.Length < 4.7 & Sepal.Length < 5.75 & Sepal.Length >= #> 5.45 ~ \"versicolor\", Petal.Length < 2.55 & Petal.Length < #> 4.95 & Sepal.Length >= 5.75 & Sepal.Length >= 5.45 ~ #> \"setosa\", Petal.Length >= 5.05 & Petal.Length >= 4.95 & #> Sepal.Length >= 5.75 & Sepal.Length >= 5.45 ~ \"virginica\", #> Petal.Width < 1.7 & Petal.Length >= 2.55 & Petal.Length < #> 4.95 & Sepal.Length >= 5.75 & Sepal.Length >= 5.45 ~ #> \"versicolor\", Petal.Width >= 1.7 & Petal.Length >= 2.55 & #> Petal.Length < 4.95 & Sepal.Length >= 5.75 & Sepal.Length >= #> 5.45 ~ \"virginica\", Sepal.Length < 6.5 & Petal.Length < #> 5.05 & Petal.Length >= 4.95 & Sepal.Length >= 5.75 & #> Sepal.Length >= 5.45 ~ \"virginica\", Sepal.Length >= 6.5 & #> Petal.Length < 5.05 & Petal.Length >= 4.95 & Sepal.Length >= #> 5.75 & Sepal.Length >= 5.45 ~ \"versicolor\")"},{"path":"https://tidypredict.tidymodels.org/articles/save.html","id":"parse-model","dir":"Articles","previous_headings":"","what":"Parse model","title":"Save and re-load models","text":"parse_model() function allows run first step manually. return R list object contains needed information produce prediction calculation. structure parsed model varies based kind model processed. general, consistent kind information expects model type. example, example lm() model object return variables sigma2, used model types, decision trees. Usually, pass R model object functions : tidypredict_fit(), tidypredict_sql(). functions also accept previously parsed model.","code":"library(tidypredict) parsed <- parse_model(model) str(parsed, 2) #> List of 2 #> $ general:List of 6 #> ..$ model : chr \"lm\" #> ..$ version : num 2 #> ..$ type : chr \"regression\" #> ..$ residual: int 26 #> ..$ sigma2 : num 5.91 #> ..$ is_glm : num 0 #> $ terms :List of 6 #> ..$ :List of 5 #> ..$ :List of 5 #> ..$ :List of 5 #> ..$ :List of 5 #> ..$ :List of 5 #> ..$ :List of 5 #> - attr(*, \"class\")= chr [1:3] \"parsed_model\" \"pm_regression\" \"list\" tidypredict_fit(parsed) #> 53.5256637443325 + (wt * -6.38154597431605) + (disp * -0.0458426921825963) + #> (cyl * -3.63025567939439) + (wt * cyl * 0.535604359938273) + #> (disp * cyl * 0.00540618405824794)"},{"path":"https://tidypredict.tidymodels.org/articles/save.html","id":"saving-the-model","dir":"Articles","previous_headings":"","what":"Saving the model","title":"Save and re-load models","text":"Saving model quite easy, use package yaml write model object YAML file. format can persist ragged list object work well.","code":"library(yaml) write_yaml(parsed, \"my_model.yml\")"},{"path":"https://tidypredict.tidymodels.org/articles/save.html","id":"re-load-the-model","dir":"Articles","previous_headings":"","what":"Re-load the model","title":"Save and re-load models","text":"new R session, can read YAML file environment. preview file looks exactly preview original parsed model. tidypredict able read new R variable use create formula. variable can used tidypredict functions, tidypredict_sql()","code":"library(tidypredict) library(yaml) loaded_model <- read_yaml(\"my_model\") loaded_model <- as_parsed_model(loaded_model) str(loaded_model, 2) #> List of 2 #> $ general:List of 6 #> ..$ model : chr \"lm\" #> ..$ version : num 2 #> ..$ type : chr \"regression\" #> ..$ residual: int 26 #> ..$ sigma2 : num 5.91 #> ..$ is_glm : num 0 #> $ terms :List of 6 #> ..$ :List of 5 #> ..$ :List of 5 #> ..$ :List of 5 #> ..$ :List of 5 #> ..$ :List of 5 #> ..$ :List of 5 #> - attr(*, \"class\")= chr [1:3] \"parsed_model\" \"pm_regression\" \"list\" tidypredict_fit(loaded_model) #> 53.5256637 + (wt * -6.381546) + (disp * -0.0458427) + (cyl * #> -3.6302557) + (wt * cyl * 0.5356044) + (disp * cyl * 0.0054062) tidypredict_sql(loaded_model, dbplyr::simulate_odbc()) #> <SQL> ((((53.5256637 + (`wt` * -6.381546)) + (`disp` * -0.0458427)) + (`cyl` * -3.6302557)) + ((`wt` * `cyl`) * 0.5356044)) + ((`disp` * `cyl`) * 0.0054062)"},{"path":"https://tidypredict.tidymodels.org/articles/save.html","id":"broom","dir":"Articles","previous_headings":"","what":"broom","title":"Save and re-load models","text":"parsed_model object integrates tidy() broom.","code":"tidy(loaded_model) #> # A tibble: 6 × 2 #> term estimate #> <chr> <dbl> #> 1 (Intercept) 53.5 #> 2 wt -6.38 #> 3 disp -0.0458 #> 4 cyl -3.63 #> 5 wt:cyl 0.536 #> 6 disp:cyl 0.00541"},{"path":"https://tidypredict.tidymodels.org/articles/sql.html","id":"example-setup","dir":"Articles","previous_headings":"","what":"Example setup","title":"Database write-back","text":"keep example reproducible, SQLite database used simulate larger scale deployment. First data prepared memory. article use nycflights13::flights data, couple modifications new database created using RSQLite.","code":"library(dplyr) library(tidypredict) library(randomForest) library(dbplyr) flights_table <- nycflights13::flights %>% mutate( current_score = 0, flight_id = row_number() ) library(DBI) con <- dbConnect(RSQLite::SQLite(), path = \":memory:\") db_fligths <- copy_to(con, flights_table)"},{"path":"https://tidypredict.tidymodels.org/articles/sql.html","id":"model-preparation","dir":"Articles","previous_headings":"","what":"Model preparation","title":"Database write-back","text":"sample downloaded database modeling. example already selects needed variables. linear model fitted using lm() highly recommendable always run tidypredict_test() make sure predictions line predict() command returns. lm glm models contain data fitted , ’s easy run test. tidypredict_test() uses model’s internal data set default cases model re-fitting automated, tidypredict_test() function returns alert case threshold exceeded, can used fail automated script.","code":"df <- db_fligths %>% select(dep_delay, hour, distance) %>% head(1000) %>% collect() model <- lm(dep_delay ~ ., data = df) tidypredict_test(model) #> tidypredict test results #> Difference threshold: 1e-12 #> #> All results are within the difference threshold if (tidypredict_test(model)$alert) stop(\"Threshold exceeded!\")"},{"path":"https://tidypredict.tidymodels.org/articles/sql.html","id":"scenario-1---update-scores","dir":"Articles","previous_headings":"","what":"Scenario 1 - Update scores","title":"Database write-back","text":"scenario, table supplies term values also recipient new score. done updating specific field table. example, field called current_score. following SQL UPDATE statement work databases: statement can passed database team, via documentation automated process. cases analyst responsibility run new SQL statement, R used automate scoring, next line can used: sample newly populated field:","code":"library(dbplyr) update_statement <- build_sql(\"UPDATE flights_table SET current_score = \", tidypredict_sql(model, con = con), con = con) update_statement #> <SQL> UPDATE flights_table SET current_score = (-3.59844229187029 + (`hour` * 1.38710560882252)) + (`distance` * -0.00307606912118568) dbSendQuery(con, update_statement) #> <SQLiteResult> #> SQL UPDATE flights_table SET current_score = (-3.59844229187029 + (`hour` * 1.38710560882252)) + (`distance` * -0.00307606912118568) #> ROWS Fetched: 0 [complete] #> Changed: 336776 db_fligths %>% select(current_score) %>% head(10) #> Warning: Closing open result set, pending rows #> # Source: SQL [?? x 1] #> # Database: sqlite 3.47.1 [] #> current_score #> <dbl> #> 1 -0.969 #> 2 -1.02 #> 3 -0.0128 #> 4 -1.51 #> 5 2.38 #> 6 1.13 #> 7 1.45 #> 8 4.02 #> 9 1.82 #> 10 2.47"},{"path":"https://tidypredict.tidymodels.org/articles/sql.html","id":"scenario-2--append-new-scores","dir":"Articles","previous_headings":"","what":"Scenario 2- Append new scores","title":"Database write-back","text":"may need retain new score, determined history. usually possible source record possesses unique key identifier per entity, transaction ID customer ID. example, flights_id unique identifier. example, new scores stored new table called daily_scores. following code part example preparation, creates table seeds single row. best way create empty table, ’ll purposes example. plan use SQL statement vendors support, called INSERT SELECT. idea use dplyr laziness prepare data transformation predictions, ’s going executed parsed SQL sent part another statement. INSERT SELECT statement allows results query saved table, without leaving database. example, predictions going executed just records month December. data filtered, tidypredict_to_column() used create new fit field. results transformed match structure new daily_scores table. first scenario, statement can passed database team, via documentation automated process. cases analyst responsibility run new SQL statement, R used automate scoring, next line can used: simple table join can used confirm new update worked. real life scenarios, sophisticated query performed order get latest score. example, simple filter date inserted","code":"dbWriteTable( con, \"daily_scores\", tibble( flight_id = 0, score = 0, date = \"\" ) ) new_predictions <- db_fligths %>% filter(month == 12) %>% tidypredict_to_column(model, vars = \"score\") %>% select( flight_id, score ) %>% mutate(date = \"01/01/2018\") insert_scores <- build_sql(\"INSERT INTO daily_scores \", sql_render(new_predictions, con = con), con = con) insert_scores #> <SQL> INSERT INTO daily_scores SELECT `q01`.*, '01/01/2018' AS `date` #> FROM ( #> SELECT #> `flight_id`, #> (-3.59844229187029 + (`hour` * 1.38710560882252)) + (`distance` * -0.00307606912118568) AS `score` #> FROM `flights_table` #> WHERE (`month` = 12.0) #> ) AS `q01` dbSendQuery(con, insert_scores) #> <SQLiteResult> #> SQL INSERT INTO daily_scores SELECT `q01`.*, '01/01/2018' AS `date` #> FROM ( #> SELECT #> `flight_id`, #> (-3.59844229187029 + (`hour` * 1.38710560882252)) + (`distance` * -0.00307606912118568) AS `score` #> FROM `flights_table` #> WHERE (`month` = 12.0) #> ) AS `q01` #> ROWS Fetched: 0 [complete] #> Changed: 28135 tbl(con, \"daily_scores\") %>% inner_join(tbl(con, \"flights_table\"), by = \"flight_id\") %>% filter(date == \"01/01/2018\") %>% select(dep_delay, hour, distance, score, date) #> Warning: Closing open result set, pending rows #> # Source: SQL [?? x 5] #> # Database: sqlite 3.47.1 [] #> dep_delay hour distance score date #> <dbl> <dbl> <dbl> <dbl> <chr> #> 1 14 23 1617 23.3 01/01/2018 #> 2 18 23 1576 23.5 01/01/2018 #> 3 -7 5 529 1.71 01/01/2018 #> 4 5 5 1400 -0.969 01/01/2018 #> 5 -4 5 1089 -0.0128 01/01/2018 #> 6 -10 5 1576 -1.51 01/01/2018 #> 7 -4 5 569 1.59 01/01/2018 #> 8 1 5 1416 -1.02 01/01/2018 #> 9 -11 6 214 4.07 01/01/2018 #> 10 -10 6 1065 1.45 01/01/2018 #> # ℹ more rows"},{"path":"https://tidypredict.tidymodels.org/articles/xgboost.html","id":"tidypredict_-functions","dir":"Articles","previous_headings":"","what":"tidypredict_ functions","title":"XGBoost models","text":"Create R formula Add prediction original table Confirm tidypredict results match model’s predict() results. xg_df argument expects xgb.DMatrix data set.","code":"library(xgboost) logregobj <- function(preds, dtrain) { labels <- xgboost::getinfo(dtrain, \"label\") preds <- 1 / (1 + exp(-preds)) grad <- preds - labels hess <- preds * (1 - preds) return(list(grad = grad, hess = hess)) } xgb_bin_data <- xgboost::xgb.DMatrix( as.matrix(mtcars[, -9]), label = mtcars$am ) model <- xgboost::xgb.train( params = list(max_depth = 2, objective = \"binary:logistic\", base_score = 0.5), data = xgb_bin_data, nrounds = 50 ) tidypredict_fit(model) #> 1 - 1/(1 + exp(0 + case_when(wt >= 3.18000007 ~ -0.436363667, #> (qsec < 19.1849995 | is.na(qsec)) & (wt < 3.18000007 | is.na(wt)) ~ #> 0.428571463, qsec >= 19.1849995 & (wt < 3.18000007 | #> is.na(wt)) ~ 0) + case_when((wt < 3.01250005 | is.na(wt)) ~ #> 0.311573088, (hp < 222.5 | is.na(hp)) & wt >= 3.01250005 ~ #> -0.392053694, hp >= 222.5 & wt >= 3.01250005 ~ -0.0240745768) + #> case_when((gear < 3.5 | is.na(gear)) ~ -0.355945677, (wt < #> 3.01250005 | is.na(wt)) & gear >= 3.5 ~ 0.325712085, #> wt >= 3.01250005 & gear >= 3.5 ~ -0.0384863913) + case_when((gear < #> 3.5 | is.na(gear)) ~ -0.309683114, (wt < 3.01250005 | is.na(wt)) & #> gear >= 3.5 ~ 0.283893973, wt >= 3.01250005 & gear >= 3.5 ~ #> -0.032039877) + case_when((gear < 3.5 | is.na(gear)) ~ -0.275577009, #> (wt < 3.01250005 | is.na(wt)) & gear >= 3.5 ~ 0.252453178, #> wt >= 3.01250005 & gear >= 3.5 ~ -0.0266750772) + case_when((gear < #> 3.5 | is.na(gear)) ~ -0.248323873, (qsec < 17.6599998 | is.na(qsec)) & #> gear >= 3.5 ~ 0.261978835, qsec >= 17.6599998 & gear >= 3.5 ~ #> -0.00959526002) + case_when((gear < 3.5 | is.na(gear)) ~ #> -0.225384533, (wt < 3.01250005 | is.na(wt)) & gear >= 3.5 ~ #> 0.218285918, wt >= 3.01250005 & gear >= 3.5 ~ -0.0373593047) + #> case_when((gear < 3.5 | is.na(gear)) ~ -0.205454513, (qsec < #> 18.7550011 | is.na(qsec)) & gear >= 3.5 ~ 0.196076646, #> qsec >= 18.7550011 & gear >= 3.5 ~ -0.0544253439) + case_when((wt < #> 3.01250005 | is.na(wt)) ~ 0.149246693, (qsec < 17.4099998 | #> is.na(qsec)) & wt >= 3.01250005 ~ 0.0354709327, qsec >= 17.4099998 & #> wt >= 3.01250005 ~ -0.226075932) + case_when((gear < 3.5 | #> is.na(gear)) ~ -0.184417158, (wt < 3.01250005 | is.na(wt)) & #> gear >= 3.5 ~ 0.176768288, wt >= 3.01250005 & gear >= 3.5 ~ #> -0.0237750355) + case_when((gear < 3.5 | is.na(gear)) ~ -0.168993726, #> (qsec < 18.6049995 | is.na(qsec)) & gear >= 3.5 ~ 0.155569643, #> qsec >= 18.6049995 & gear >= 3.5 ~ -0.0325752236) + case_when((wt < #> 3.01250005 | is.na(wt)) ~ 0.119126029, wt >= 3.01250005 ~ #> -0.105012275) + case_when((qsec < 17.1749992 | is.na(qsec)) ~ #> 0.117254697, qsec >= 17.1749992 ~ -0.0994235724) + case_when((wt < #> 3.18000007 | is.na(wt)) ~ 0.097100094, wt >= 3.18000007 ~ #> -0.10567718) + case_when((wt < 3.18000007 | is.na(wt)) ~ #> 0.0824323222, wt >= 3.18000007 ~ -0.091120176) + case_when((qsec < #> 17.5100002 | is.na(qsec)) ~ 0.0854752287, qsec >= 17.5100002 ~ #> -0.0764453933) + case_when((wt < 3.18000007 | is.na(wt)) ~ #> 0.0749477893, wt >= 3.18000007 ~ -0.0799863264) + case_when((qsec < #> 17.7099991 | is.na(qsec)) ~ 0.0728750378, qsec >= 17.7099991 ~ #> -0.0646049976) + case_when((wt < 3.18000007 | is.na(wt)) ~ #> 0.0682478622, wt >= 3.18000007 ~ -0.0711427554) + case_when((wt < #> 3.18000007 | is.na(wt)) ~ 0.0579533465, wt >= 3.18000007 ~ #> -0.0613371208) + case_when((qsec < 18.1499996 | is.na(qsec)) ~ #> 0.0595484748, qsec >= 18.1499996 ~ -0.0546668135) + case_when((wt < #> 3.18000007 | is.na(wt)) ~ 0.0535288528, wt >= 3.18000007 ~ #> -0.0558333211) + case_when((wt < 3.18000007 | is.na(wt)) ~ #> 0.0454574414, wt >= 3.18000007 ~ -0.048143398) + case_when((qsec < #> 18.5600014 | is.na(qsec)) ~ 0.0422042683, qsec >= 18.5600014 ~ #> -0.0454404354) + case_when((wt < 3.18000007 | is.na(wt)) ~ #> 0.0420555808, wt >= 3.18000007 ~ -0.0449385941) + case_when((qsec < #> 18.5600014 | is.na(qsec)) ~ 0.0393446013, qsec >= 18.5600014 ~ #> -0.0425945036) + case_when((wt < 3.18000007 | is.na(wt)) ~ #> 0.0391179025, wt >= 3.18000007 ~ -0.0420661867) + case_when((qsec < #> 18.4099998 | is.na(qsec)) ~ 0.0304145869, qsec >= 18.4099998 ~ #> -0.031833414) + case_when((wt < 3.18000007 | is.na(wt)) ~ #> 0.0362136625, wt >= 3.18000007 ~ -0.038949281) + case_when((qsec < #> 18.4099998 | is.na(qsec)) ~ 0.0295153651, qsec >= 18.4099998 ~ #> -0.0307046026) + case_when((drat < 3.80999994 | is.na(drat)) ~ #> -0.0306891855, drat >= 3.80999994 ~ 0.0288283136) + case_when((qsec < #> 18.4099998 | is.na(qsec)) ~ 0.0271221269, qsec >= 18.4099998 ~ #> -0.0281750448) + case_when((qsec < 18.4099998 | is.na(qsec)) ~ #> 0.0228891298, qsec >= 18.4099998 ~ -0.0238814205) + case_when((drat < #> 3.80999994 | is.na(drat)) ~ -0.0296511576, drat >= 3.80999994 ~ #> 0.0280048084) + case_when((qsec < 18.4099998 | is.na(qsec)) ~ #> 0.0214707125, qsec >= 18.4099998 ~ -0.0224219449) + case_when((qsec < #> 18.4099998 | is.na(qsec)) ~ 0.0181306079, qsec >= 18.4099998 ~ #> -0.0190209728) + case_when((wt < 3.18000007 | is.na(wt)) ~ #> 0.0379650332, wt >= 3.18000007 ~ -0.0395050682) + case_when((qsec < #> 18.4099998 | is.na(qsec)) ~ 0.0194106717, qsec >= 18.4099998 ~ #> -0.0202215631) + case_when((qsec < 18.4099998 | is.na(qsec)) ~ #> 0.0164139606, qsec >= 18.4099998 ~ -0.0171694476) + case_when((qsec < #> 18.4099998 | is.na(qsec)) ~ 0.013879573, qsec >= 18.4099998 ~ #> -0.0145772668) + case_when((qsec < 18.4099998 | is.na(qsec)) ~ #> 0.0117362784, qsec >= 18.4099998 ~ -0.0123759825) + case_when((wt < #> 3.18000007 | is.na(wt)) ~ 0.0388614088, wt >= 3.18000007 ~ #> -0.0400568396) + log(0.5/(1 - 0.5)))) library(dplyr) mtcars %>% tidypredict_to_column(model) %>% glimpse() #> Rows: 32 #> Columns: 12 #> $ mpg <dbl> 21.0, 21.0, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4, 22.8, 19.2,… #> $ cyl <dbl> 6, 6, 4, 6, 8, 6, 8, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 4, 4, 4,… #> $ disp <dbl> 160.0, 160.0, 108.0, 258.0, 360.0, 225.0, 360.0, 146.7, 140… #> $ hp <dbl> 110, 110, 93, 110, 175, 105, 245, 62, 95, 123, 123, 180, 18… #> $ drat <dbl> 3.90, 3.90, 3.85, 3.08, 3.15, 2.76, 3.21, 3.69, 3.92, 3.92,… #> $ wt <dbl> 2.620, 2.875, 2.320, 3.215, 3.440, 3.460, 3.570, 3.190, 3.1… #> $ qsec <dbl> 16.46, 17.02, 18.61, 19.44, 17.02, 20.22, 15.84, 20.00, 22.… #> $ vs <dbl> 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1,… #> $ am <dbl> 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,… #> $ gear <dbl> 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4, 4,… #> $ carb <dbl> 4, 4, 1, 1, 2, 1, 4, 2, 2, 4, 4, 3, 3, 3, 4, 4, 4, 1, 2, 1,… #> $ fit <dbl> 0.98576418, 0.98576418, 0.92735110, 0.01081509, 0.04639094,… tidypredict_test(model, mtcars, xg_df = xgb_bin_data) #> tidypredict test results #> Difference threshold: 1e-12 #> #> All results are within the difference threshold"},{"path":"https://tidypredict.tidymodels.org/articles/xgboost.html","id":"parsnip","dir":"Articles","previous_headings":"","what":"parsnip","title":"XGBoost models","text":"parsnip fitted models also supported tidypredict:","code":"library(parsnip) p_model <- boost_tree(mode = \"regression\") %>% set_engine(\"xgboost\") %>% fit(am ~ ., data = mtcars) tidypredict_test(p_model, mtcars, xg_df = xgb_bin_data) #> tidypredict test results #> Difference threshold: 1e-12 #> #> Fitted records above the threshold: 15 #> #> Fit max difference: #> Lower max difference: #> Upper max difference:8.06462707725331e-08"},{"path":"https://tidypredict.tidymodels.org/articles/xgboost.html","id":"parse-model-spec","dir":"Articles","previous_headings":"","what":"Parse model spec","title":"XGBoost models","text":"example model spec:","code":"pm <- parse_model(model) str(pm, 2) #> List of 2 #> $ general:List of 7 #> ..$ model : chr \"xgb.Booster\" #> ..$ type : chr \"xgb\" #> ..$ niter : num 50 #> ..$ params :List of 4 #> ..$ feature_names: chr [1:10] \"mpg\" \"cyl\" \"disp\" \"hp\" ... #> ..$ nfeatures : int 10 #> ..$ version : num 1 #> $ trees :List of 42 #> ..$ 0 :List of 3 #> ..$ 1 :List of 3 #> ..$ 2 :List of 3 #> ..$ 3 :List of 3 #> ..$ 4 :List of 3 #> ..$ 5 :List of 3 #> ..$ 6 :List of 3 #> ..$ 7 :List of 3 #> ..$ 8 :List of 3 #> ..$ 9 :List of 3 #> ..$ 10:List of 3 #> ..$ 11:List of 2 #> ..$ 12:List of 2 #> ..$ 13:List of 2 #> ..$ 14:List of 2 #> ..$ 15:List of 2 #> ..$ 16:List of 2 #> ..$ 17:List of 2 #> ..$ 18:List of 2 #> ..$ 19:List of 2 #> ..$ 20:List of 2 #> ..$ 21:List of 2 #> ..$ 22:List of 2 #> ..$ 23:List of 2 #> ..$ 24:List of 2 #> ..$ 25:List of 2 #> ..$ 26:List of 2 #> ..$ 27:List of 2 #> ..$ 28:List of 2 #> ..$ 29:List of 2 #> ..$ 30:List of 2 #> ..$ 31:List of 2 #> ..$ 32:List of 2 #> ..$ 33:List of 2 #> ..$ 34:List of 2 #> ..$ 35:List of 2 #> ..$ 36:List of 2 #> ..$ 37:List of 2 #> ..$ 38:List of 2 #> ..$ 39:List of 2 #> ..$ 40:List of 2 #> ..$ 41:List of 2 #> - attr(*, \"class\")= chr [1:3] \"parsed_model\" \"pm_xgb\" \"list\" str(pm$trees[1]) #> List of 1 #> $ 0:List of 3 #> ..$ :List of 2 #> .. ..$ prediction: num -0.436 #> .. ..$ path :List of 1 #> .. .. ..$ :List of 5 #> .. .. .. ..$ type : chr \"conditional\" #> .. .. .. ..$ col : chr \"wt\" #> .. .. .. ..$ val : num 3.18 #> .. .. .. ..$ op : chr \"less\" #> .. .. .. ..$ missing: logi FALSE #> ..$ :List of 2 #> .. ..$ prediction: num 0.429 #> .. ..$ path :List of 2 #> .. .. ..$ :List of 5 #> .. .. .. ..$ type : chr \"conditional\" #> .. .. .. ..$ col : chr \"qsec\" #> .. .. .. ..$ val : num 19.2 #> .. .. .. ..$ op : chr \"more-equal\" #> .. .. .. ..$ missing: logi TRUE #> .. .. ..$ :List of 5 #> .. .. .. ..$ type : chr \"conditional\" #> .. .. .. ..$ col : chr \"wt\" #> .. .. .. ..$ val : num 3.18 #> .. .. .. ..$ op : chr \"more-equal\" #> .. .. .. ..$ missing: logi TRUE #> ..$ :List of 2 #> .. ..$ prediction: num 0 #> .. ..$ path :List of 2 #> .. .. ..$ :List of 5 #> .. .. .. ..$ type : chr \"conditional\" #> .. .. .. ..$ col : chr \"qsec\" #> .. .. .. ..$ val : num 19.2 #> .. .. .. ..$ op : chr \"less\" #> .. .. .. ..$ missing: logi FALSE #> .. .. ..$ :List of 5 #> .. .. .. ..$ type : chr \"conditional\" #> .. .. .. ..$ col : chr \"wt\" #> .. .. .. ..$ val : num 3.18 #> .. .. .. ..$ op : chr \"more-equal\" #> .. .. .. ..$ missing: logi TRUE"},{"path":"https://tidypredict.tidymodels.org/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Emil Hvitfeldt. Author, maintainer. Edgar Ruiz. Author. Max Kuhn. Author.","code":""},{"path":"https://tidypredict.tidymodels.org/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Hvitfeldt E, Ruiz E, Kuhn M (2024). tidypredict: Run Predictions Inside Database. R package version 0.5.1.9000, https://github.com/tidymodels/tidypredict, https://tidypredict.tidymodels.org.","code":"@Manual{, title = {tidypredict: Run Predictions Inside the Database}, author = {Emil Hvitfeldt and Edgar Ruiz and Max Kuhn}, year = {2024}, note = {R package version 0.5.1.9000, https://github.com/tidymodels/tidypredict}, url = {https://tidypredict.tidymodels.org}, }"},{"path":"https://tidypredict.tidymodels.org/index.html","id":"tidypredict-","dir":"","previous_headings":"","what":"Run Predictions Inside the Database","title":"Run Predictions Inside the Database","text":"main goal tidypredict enable running predictions inside databases. reads model, extracts components needed calculate prediction, creates R formula can translated SQL. words, able parse model one: tidypredict can return SQL statement ready run inside database. uses dplyr’s database interface, works several databases back-ends, MS SQL:","code":"model <- lm(mpg ~ wt + cyl, data = mtcars) tidypredict_sql(model, dbplyr::simulate_mssql()) ## <SQL> (39.686261480253 + (`wt` * -3.19097213898374)) + (`cyl` * -1.5077949682598)"},{"path":"https://tidypredict.tidymodels.org/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Run Predictions Inside the Database","text":"Install tidypredict CRAN using: install development version using devtools follows:","code":"install.packages(\"tidypredict\") install.packages(\"remotes\") remotes::install_github(\"tidymodels/tidypredict\")"},{"path":"https://tidypredict.tidymodels.org/index.html","id":"functions","dir":"","previous_headings":"","what":"Functions","title":"Run Predictions Inside the Database","text":"tidypredict functions, expected number grow much. main focus time add models support.","code":""},{"path":"https://tidypredict.tidymodels.org/index.html","id":"how-it-works","dir":"","previous_headings":"","what":"How it works","title":"Run Predictions Inside the Database","text":"Instead translating directly SQL statement, tidypredict creates R formula. formula can used inside dplyr. overall workflow illustrated image , described : Fit model using base R model, one packages listed Supported Models tidypredict reads model, creates list object necessary components run predictions tidypredict builds R formula based list object dplyr evaluates formula created tidypredict dplyr translates formula SQL statement, interfaces. database executes SQL statement(s) created dplyr","code":""},{"path":"https://tidypredict.tidymodels.org/index.html","id":"parsed-model-spec","dir":"","previous_headings":"How it works","what":"Parsed model spec","title":"Run Predictions Inside the Database","text":"tidypredict writes reads spec based model. Instead simply writing R formula directly, splitting spec formula adds following capabilities: saving models .rds - Specifically cases model needs used predictions Shiny app. Beyond R models - Technically, anything can write proper spec, can read tidypredict. also means, parsed model spec can become good alternative using PMML.","code":""},{"path":"https://tidypredict.tidymodels.org/index.html","id":"supported-models","dir":"","previous_headings":"","what":"Supported models","title":"Run Predictions Inside the Database","text":"following models supported tidypredict: Linear Regression - lm() Generalized Linear model - glm() Random Forest models - randomForest::randomForest() Random Forest models, via ranger - ranger::ranger() MARS models - earth::earth() XGBoost models - xgboost::xgb.Booster.complete() Cubist models - Cubist::cubist() Tree models, via partykit - partykit::ctree()","code":""},{"path":"https://tidypredict.tidymodels.org/index.html","id":"parsnip","dir":"","previous_headings":"Supported models","what":"parsnip","title":"Run Predictions Inside the Database","text":"tidypredict supports models fitted via parsnip interface. ones confirmed currently work tidypredict : lm() - parsnip: linear_reg() “lm” engine. randomForest::randomForest() - parsnip: rand_forest() “randomForest” engine. ranger::ranger() - parsnip: rand_forest() “ranger” engine. earth::earth() - parsnip: mars() “earth” engine.","code":""},{"path":"https://tidypredict.tidymodels.org/index.html","id":"broom","dir":"","previous_headings":"Supported models","what":"broom","title":"Run Predictions Inside the Database","text":"tidy() function broom works linear models parsed via tidypredict","code":"pm <- parse_model(lm(wt ~ ., mtcars)) tidy(pm) ## # A tibble: 11 × 2 ## term estimate ## <chr> <dbl> ## 1 (Intercept) -0.231 ## 2 mpg -0.0417 ## 3 cyl -0.0573 ## 4 disp 0.00669 ## 5 hp -0.00323 ## 6 drat -0.0901 ## 7 qsec 0.200 ## 8 vs -0.0664 ## 9 am 0.0184 ## 10 gear -0.0935 ## 11 carb 0.249"},{"path":"https://tidypredict.tidymodels.org/index.html","id":"contributing","dir":"","previous_headings":"","what":"Contributing","title":"Run Predictions Inside the Database","text":"project released Contributor Code Conduct. contributing project, agree abide terms. questions discussions tidymodels packages, modeling, machine learning, please post Posit Community. think encountered bug, please submit issue. Either way, learn create share reprex (minimal, reproducible example), clearly communicate code. Check details contributing guidelines tidymodels packages get help.","code":""},{"path":"https://tidypredict.tidymodels.org/reference/acceptable_formula.html","id":null,"dir":"Reference","previous_headings":"","what":"Checks that the formula can be parsed — acceptable_formula","title":"Checks that the formula can be parsed — acceptable_formula","text":"Uses S3 method check given formula can parsed based class. currently scans contrasts supported -line functions. (e.g: lm(wt ~ .factor())). Since function meant function interaction, opposed human interaction, successful check silent.","code":""},{"path":"https://tidypredict.tidymodels.org/reference/acceptable_formula.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Checks that the formula can be parsed — acceptable_formula","text":"","code":"acceptable_formula(model)"},{"path":"https://tidypredict.tidymodels.org/reference/acceptable_formula.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Checks that the formula can be parsed — acceptable_formula","text":"model R model object","code":""},{"path":"https://tidypredict.tidymodels.org/reference/acceptable_formula.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Checks that the formula can be parsed — acceptable_formula","text":"","code":"model <- lm(mpg ~ wt, mtcars) acceptable_formula(model)"},{"path":"https://tidypredict.tidymodels.org/reference/as_parsed_model.html","id":null,"dir":"Reference","previous_headings":"","what":"Prepares parsed model object — as_parsed_model","title":"Prepares parsed model object — as_parsed_model","text":"Prepares parsed model object","code":""},{"path":"https://tidypredict.tidymodels.org/reference/as_parsed_model.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Prepares parsed model object — as_parsed_model","text":"","code":"as_parsed_model(x)"},{"path":"https://tidypredict.tidymodels.org/reference/as_parsed_model.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Prepares parsed model object — as_parsed_model","text":"x parsed model object","code":""},{"path":"https://tidypredict.tidymodels.org/reference/dot-extract_partykit_classprob.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract classprob trees for partykit models — .extract_partykit_classprob","title":"Extract classprob trees for partykit models — .extract_partykit_classprob","text":"use orbital package.","code":""},{"path":"https://tidypredict.tidymodels.org/reference/dot-extract_partykit_classprob.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract classprob trees for partykit models — .extract_partykit_classprob","text":"","code":".extract_partykit_classprob(model)"},{"path":"https://tidypredict.tidymodels.org/reference/dot-extract_xgb_trees.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract processed xgboost trees — .extract_xgb_trees","title":"Extract processed xgboost trees — .extract_xgb_trees","text":"use orbital package.","code":""},{"path":"https://tidypredict.tidymodels.org/reference/dot-extract_xgb_trees.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract processed xgboost trees — .extract_xgb_trees","text":"","code":".extract_xgb_trees(model)"},{"path":"https://tidypredict.tidymodels.org/reference/knit_print.tidypredict_test.html","id":null,"dir":"Reference","previous_headings":"","what":"Knit print method for test predictions results — knit_print.tidypredict_test","title":"Knit print method for test predictions results — knit_print.tidypredict_test","text":"Knit print method test predictions results","code":""},{"path":"https://tidypredict.tidymodels.org/reference/knit_print.tidypredict_test.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Knit print method for test predictions results — knit_print.tidypredict_test","text":"","code":"# S3 method for class 'tidypredict_test' knit_print(x, ...)"},{"path":"https://tidypredict.tidymodels.org/reference/parse_model.html","id":null,"dir":"Reference","previous_headings":"","what":"Converts an R model object into a table. — parse_model","title":"Converts an R model object into a table. — parse_model","text":"parses fitted R model's structure extracts components needed create dplyr formula prediction. function also creates data frame using specific format functions future can also pass parsed tables given formula creating function.","code":""},{"path":"https://tidypredict.tidymodels.org/reference/parse_model.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Converts an R model object into a table. — parse_model","text":"","code":"parse_model(model)"},{"path":"https://tidypredict.tidymodels.org/reference/parse_model.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Converts an R model object into a table. — parse_model","text":"model R model object.","code":""},{"path":"https://tidypredict.tidymodels.org/reference/parse_model.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Converts an R model object into a table. — parse_model","text":"","code":"library(dplyr) #> #> Attaching package: ‘dplyr’ #> The following objects are masked from ‘package:stats’: #> #> filter, lag #> The following objects are masked from ‘package:base’: #> #> intersect, setdiff, setequal, union df <- mutate(mtcars, cyl = paste0(\"cyl\", cyl)) model <- lm(mpg ~ wt + cyl * disp, offset = am, data = df) parse_model(model) #> $general #> $general$model #> [1] \"lm\" #> #> $general$version #> [1] 2 #> #> $general$type #> [1] \"regression\" #> #> $general$residual #> [1] 25 #> #> $general$sigma2 #> [1] 5.414866 #> #> $general$offset #> am #> #> $general$is_glm #> [1] 0 #> #> #> $terms #> $terms[[1]] #> $terms[[1]]$label #> [1] \"(Intercept)\" #> #> $terms[[1]]$coef #> [1] 39.41278 #> #> $terms[[1]]$is_intercept #> [1] 1 #> #> $terms[[1]]$fields #> $terms[[1]]$fields[[1]] #> $terms[[1]]$fields[[1]]$type #> [1] \"ordinary\" #> #> $terms[[1]]$fields[[1]]$col #> [1] \"(Intercept)\" #> #> #> #> $terms[[1]]$qr #> $terms[[1]]$qr$qr_1 #> [1] -0.1767767 #> #> $terms[[1]]$qr$qr_2 #> [1] -0.5905573 #> #> $terms[[1]]$qr$qr_3 #> [1] -0.1262157 #> #> $terms[[1]]$qr$qr_4 #> [1] 0.3862155 #> #> $terms[[1]]$qr$qr_5 #> [1] -0.1536563 #> #> $terms[[1]]$qr$qr_6 #> [1] -0.02235892 #> #> $terms[[1]]$qr$qr_7 #> [1] 1.040622 #> #> #> #> $terms[[2]] #> $terms[[2]]$label #> [1] \"wt\" #> #> $terms[[2]]$coef #> [1] -1.619173 #> #> $terms[[2]]$is_intercept #> [1] 0 #> #> $terms[[2]]$fields #> $terms[[2]]$fields[[1]] #> $terms[[2]]$fields[[1]]$type #> [1] \"ordinary\" #> #> $terms[[2]]$fields[[1]]$col #> [1] \"wt\" #> #> #> #> $terms[[2]]$qr #> $terms[[2]]$qr$qr_1 #> [1] 0 #> #> $terms[[2]]$qr$qr_2 #> [1] 0.1835596 #> #> $terms[[2]]$qr$qr_3 #> [1] 0.01011187 #> #> $terms[[2]]$qr$qr_4 #> [1] -0.2305162 #> #> $terms[[2]]$qr$qr_5 #> [1] 0.3054412 #> #> $terms[[2]]$qr$qr_6 #> [1] -0.09551174 #> #> $terms[[2]]$qr$qr_7 #> [1] 0.156527 #> #> #> #> $terms[[3]] #> $terms[[3]]$label #> [1] \"cylcyl6\" #> #> $terms[[3]]$coef #> [1] -18.41701 #> #> $terms[[3]]$is_intercept #> [1] 0 #> #> $terms[[3]]$fields #> $terms[[3]]$fields[[1]] #> $terms[[3]]$fields[[1]]$type #> [1] \"conditional\" #> #> $terms[[3]]$fields[[1]]$col #> [1] \"cyl\" #> #> $terms[[3]]$fields[[1]]$val #> [1] \"cyl6\" #> #> $terms[[3]]$fields[[1]]$op #> [1] \"equal\" #> #> #> #> $terms[[3]]$qr #> $terms[[3]]$qr$qr_1 #> [1] 0 #> #> $terms[[3]]$qr$qr_2 #> [1] 0 #> #> $terms[[3]]$qr$qr_3 #> [1] 0.4282663 #> #> $terms[[3]]$qr$qr_4 #> [1] 0.3323365 #> #> $terms[[3]]$qr$qr_5 #> [1] 0.1509332 #> #> $terms[[3]]$qr$qr_6 #> [1] 1.88383 #> #> $terms[[3]]$qr$qr_7 #> [1] -1.412292 #> #> #> #> $terms[[4]] #> $terms[[4]]$label #> [1] \"cylcyl8\" #> #> $terms[[4]]$coef #> [1] -16.20665 #> #> $terms[[4]]$is_intercept #> [1] 0 #> #> $terms[[4]]$fields #> $terms[[4]]$fields[[1]] #> $terms[[4]]$fields[[1]]$type #> [1] \"conditional\" #> #> $terms[[4]]$fields[[1]]$col #> [1] \"cyl\" #> #> $terms[[4]]$fields[[1]]$val #> [1] \"cyl8\" #> #> $terms[[4]]$fields[[1]]$op #> [1] \"equal\" #> #> #> #> $terms[[4]]$qr #> $terms[[4]]$qr$qr_1 #> [1] 0 #> #> $terms[[4]]$qr$qr_2 #> [1] 0 #> #> $terms[[4]]$qr$qr_3 #> [1] 0 #> #> $terms[[4]]$qr$qr_4 #> [1] 0.6462039 #> #> $terms[[4]]$qr$qr_5 #> [1] 0.7608288 #> #> $terms[[4]]$qr$qr_6 #> [1] -0.4039674 #> #> $terms[[4]]$qr$qr_7 #> [1] -1.645469 #> #> #> #> $terms[[5]] #> $terms[[5]]$label #> [1] \"disp\" #> #> $terms[[5]]$coef #> [1] -0.09297857 #> #> $terms[[5]]$is_intercept #> [1] 0 #> #> $terms[[5]]$fields #> $terms[[5]]$fields[[1]] #> $terms[[5]]$fields[[1]]$type #> [1] \"ordinary\" #> #> $terms[[5]]$fields[[1]]$col #> [1] \"disp\" #> #> #> #> $terms[[5]]$qr #> $terms[[5]]$qr$qr_1 #> [1] 0 #> #> $terms[[5]]$qr$qr_2 #> [1] 0 #> #> $terms[[5]]$qr$qr_3 #> [1] 0 #> #> $terms[[5]]$qr$qr_4 #> [1] 0 #> #> $terms[[5]]$qr$qr_5 #> [1] -0.005178979 #> #> $terms[[5]]$qr$qr_6 #> [1] 0.002289148 #> #> $terms[[5]]$qr$qr_7 #> [1] -0.01330082 #> #> #> #> $terms[[6]] #> $terms[[6]]$label #> [1] \"cylcyl6:disp\" #> #> $terms[[6]]$coef #> [1] 0.1113389 #> #> $terms[[6]]$is_intercept #> [1] 0 #> #> $terms[[6]]$fields #> $terms[[6]]$fields[[1]] #> $terms[[6]]$fields[[1]]$type #> [1] \"conditional\" #> #> $terms[[6]]$fields[[1]]$col #> [1] \"cyl\" #> #> $terms[[6]]$fields[[1]]$val #> [1] \"cyl6\" #> #> $terms[[6]]$fields[[1]]$op #> [1] \"equal\" #> #> #> $terms[[6]]$fields[[2]] #> $terms[[6]]$fields[[2]]$type #> [1] \"ordinary\" #> #> $terms[[6]]$fields[[2]]$col #> [1] \"disp\" #> #> #> #> $terms[[6]]$qr #> $terms[[6]]$qr$qr_1 #> [1] 0 #> #> $terms[[6]]$qr$qr_2 #> [1] 0 #> #> $terms[[6]]$qr$qr_3 #> [1] 0 #> #> $terms[[6]]$qr$qr_4 #> [1] 0 #> #> $terms[[6]]$qr$qr_5 #> [1] 0 #> #> $terms[[6]]$qr$qr_6 #> [1] -0.01081956 #> #> $terms[[6]]$qr$qr_7 #> [1] 0.01266668 #> #> #> #> $terms[[7]] #> $terms[[7]]$label #> [1] \"cylcyl8:disp\" #> #> $terms[[7]]$coef #> [1] 0.08795571 #> #> $terms[[7]]$is_intercept #> [1] 0 #> #> $terms[[7]]$fields #> $terms[[7]]$fields[[1]] #> $terms[[7]]$fields[[1]]$type #> [1] \"conditional\" #> #> $terms[[7]]$fields[[1]]$col #> [1] \"cyl\" #> #> $terms[[7]]$fields[[1]]$val #> [1] \"cyl8\" #> #> $terms[[7]]$fields[[1]]$op #> [1] \"equal\" #> #> #> $terms[[7]]$fields[[2]] #> $terms[[7]]$fields[[2]]$type #> [1] \"ordinary\" #> #> $terms[[7]]$fields[[2]]$col #> [1] \"disp\" #> #> #> #> $terms[[7]]$qr #> $terms[[7]]$qr$qr_1 #> [1] 0 #> #> $terms[[7]]$qr$qr_2 #> [1] 0 #> #> $terms[[7]]$qr$qr_3 #> [1] 0 #> #> $terms[[7]]$qr$qr_4 #> [1] 0 #> #> $terms[[7]]$qr$qr_5 #> [1] 0 #> #> $terms[[7]]$qr$qr_6 #> [1] 0 #> #> $terms[[7]]$qr$qr_7 #> [1] 0.01324096 #> #> #> #> #> attr(,\"class\") #> [1] \"parsed_model\" \"pm_regression\" \"list\""},{"path":"https://tidypredict.tidymodels.org/reference/print.tidypredict_test.html","id":null,"dir":"Reference","previous_headings":"","what":"print method for test predictions results — print.tidypredict_test","title":"print method for test predictions results — print.tidypredict_test","text":"print method test predictions results","code":""},{"path":"https://tidypredict.tidymodels.org/reference/print.tidypredict_test.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"print method for test predictions results — print.tidypredict_test","text":"","code":"# S3 method for class 'tidypredict_test' print(x, ...)"},{"path":"https://tidypredict.tidymodels.org/reference/reexports.html","id":null,"dir":"Reference","previous_headings":"","what":"Objects exported from other packages — reexports","title":"Objects exported from other packages — reexports","text":"objects imported packages. Follow links see documentation. generics tidy","code":""},{"path":"https://tidypredict.tidymodels.org/reference/tidy.pm_regression.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidy the parsed model results — tidy.pm_regression","title":"Tidy the parsed model results — tidy.pm_regression","text":"Tidy parsed model results","code":""},{"path":"https://tidypredict.tidymodels.org/reference/tidy.pm_regression.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidy the parsed model results — tidy.pm_regression","text":"","code":"# S3 method for class 'pm_regression' tidy(x, ...)"},{"path":"https://tidypredict.tidymodels.org/reference/tidy.pm_regression.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidy the parsed model results — tidy.pm_regression","text":"x parsed_model object ... Reserved future use","code":""},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict-package.html","id":null,"dir":"Reference","previous_headings":"","what":"tidypredict: Run Predictions Inside the Database — tidypredict-package","title":"tidypredict: Run Predictions Inside the Database — tidypredict-package","text":"parses fitted 'R' model object, returns formula 'Tidy Eval' code calculates predictions. works several databases back-ends leverages 'dplyr' 'dbplyr' final 'SQL' translation algorithm. currently supports lm(), glm(), randomForest(), ranger(), earth(), xgb.Booster.complete(), cubist(), ctree() models.","code":""},{"path":[]},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"tidypredict: Run Predictions Inside the Database — tidypredict-package","text":"Maintainer: Emil Hvitfeldt [email protected] Authors: Edgar Ruiz [email protected] Max Kuhn [email protected]","code":""},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_fit.html","id":null,"dir":"Reference","previous_headings":"","what":"Returns a Tidy Eval formula to calculate fitted values — tidypredict_fit","title":"Returns a Tidy Eval formula to calculate fitted values — tidypredict_fit","text":"parses model uses already parsed model return Tidy Eval formula can used inside dplyr command.","code":""},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_fit.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Returns a Tidy Eval formula to calculate fitted values — tidypredict_fit","text":"","code":"tidypredict_fit(model)"},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_fit.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Returns a Tidy Eval formula to calculate fitted values — tidypredict_fit","text":"model R model list parsed model.","code":""},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_fit.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Returns a Tidy Eval formula to calculate fitted values — tidypredict_fit","text":"","code":"model <- lm(mpg ~ wt + cyl * disp, offset = am, data = mtcars) tidypredict_fit(model) #> 46.9691423291322 + (wt * -2.43434983315996) + (cyl * -2.86061920499755) + #> (disp * -0.0765223074908513) + (cyl * disp * 0.00981028601947223) + #> am"},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_interval.html","id":null,"dir":"Reference","previous_headings":"","what":"Returns a Tidy Eval formula to calculate prediction interval. — tidypredict_interval","title":"Returns a Tidy Eval formula to calculate prediction interval. — tidypredict_interval","text":"parses model uses already parsed model return Tidy Eval formula can used inside dplyr command.","code":""},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_interval.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Returns a Tidy Eval formula to calculate prediction interval. — tidypredict_interval","text":"","code":"tidypredict_interval(model, interval = 0.95)"},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_interval.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Returns a Tidy Eval formula to calculate prediction interval. — tidypredict_interval","text":"model R model list parsed model interval prediction interval, defaults 0.95","code":""},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_interval.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Returns a Tidy Eval formula to calculate prediction interval. — tidypredict_interval","text":"result still added subtracted fit obtain upper lower bound respectively.","code":""},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_interval.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Returns a Tidy Eval formula to calculate prediction interval. — tidypredict_interval","text":"","code":"model <- lm(mpg ~ wt + cyl * disp, offset = am, data = mtcars) tidypredict_interval(model) #> 2.05183051648029 * sqrt((-0.176776695296637) * (-0.176776695296637) * #> 6.20704821338125 + (-0.590557271637747 + wt * 0.183559646169165) * #> (-0.590557271637747 + wt * 0.183559646169165) * 6.20704821338125 + #> (-0.257207134290773 + wt * -0.230680634727453 + cyl * 0.161513439412957) * #> (-0.257207134290773 + wt * -0.230680634727453 + cyl * #> 0.161513439412957) * 6.20704821338125 + (-0.868335233010594 + #> wt * 0.271667738147758 + cyl * 0.169308509351746 + disp * #> -0.00456516834027639) * (-0.868335233010594 + wt * 0.271667738147758 + #> cyl * 0.169308509351746 + disp * -0.00456516834027639) * #> 6.20704821338125 + (-1.53184887490412 + wt * -0.163034819828352 + #> cyl * 0.221405540626369 + disp * 0.0170837100474746 + cyl * #> disp * -0.0020081028047214) * (-1.53184887490412 + wt * -0.163034819828352 + #> cyl * 0.221405540626369 + disp * 0.0170837100474746 + cyl * #> disp * -0.0020081028047214) * 6.20704821338125 + 6.20704821338125)"},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_sql.html","id":null,"dir":"Reference","previous_headings":"","what":"Returns a SQL query with formula to calculate fitted values — tidypredict_sql","title":"Returns a SQL query with formula to calculate fitted values — tidypredict_sql","text":"Returns SQL query formula calculate fitted values","code":""},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_sql.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Returns a SQL query with formula to calculate fitted values — tidypredict_sql","text":"","code":"tidypredict_sql(model, con)"},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_sql.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Returns a SQL query with formula to calculate fitted values — tidypredict_sql","text":"model R model list parsed model con Database connection object. used select correct SQL translation syntax.","code":""},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_sql.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Returns a SQL query with formula to calculate fitted values — tidypredict_sql","text":"","code":"library(dbplyr) #> #> Attaching package: ‘dbplyr’ #> The following objects are masked from ‘package:dplyr’: #> #> ident, sql model <- lm(mpg ~ wt + am + cyl, data = mtcars) tidypredict_sql(model, simulate_dbi()) #> <SQL> ((39.4179334351865 + (`wt` * -3.12514220026708)) + (`am` * 0.176493157719672)) + (`cyl` * -1.5102456624971)"},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_sql_interval.html","id":null,"dir":"Reference","previous_headings":"","what":"Returns a SQL query with formula to calculate predicted interval — tidypredict_sql_interval","title":"Returns a SQL query with formula to calculate predicted interval — tidypredict_sql_interval","text":"Returns SQL query formula calculate predicted interval","code":""},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_sql_interval.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Returns a SQL query with formula to calculate predicted interval — tidypredict_sql_interval","text":"","code":"tidypredict_sql_interval(model, con, interval = 0.95)"},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_sql_interval.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Returns a SQL query with formula to calculate predicted interval — tidypredict_sql_interval","text":"model R model tibble parsed model con Database connection object. used select correct SQL translation syntax. interval prediction interval, defaults 0.95","code":""},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_sql_interval.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Returns a SQL query with formula to calculate predicted interval — tidypredict_sql_interval","text":"","code":"library(dbplyr) model <- lm(mpg ~ wt + am + cyl, data = mtcars) tidypredict_sql_interval(model, simulate_dbi()) #> <SQL> 2.04840714179524 * SQRT(((((((-0.176776695296637) * (-0.176776695296637)) * 6.8231093058295) + ((-0.590557271637747 + `wt` * 0.183559646169165) * (-0.590557271637747 + `wt` * 0.183559646169165)) * 6.8231093058295) + (((0.769566489443369 + `wt` * -0.176199380745393) + `am` * -0.498926847360626) * ((0.769566489443369 + `wt` * -0.176199380745393) + `am` * -0.498926847360626)) * 6.8231093058295) + ((((-0.224404416240187 + `wt` * -0.23845787029348) + `am` * -0.0214203331902854) + `cyl` * 0.161662223806132) * (((-0.224404416240187 + `wt` * -0.23845787029348) + `am` * -0.0214203331902854) + `cyl` * 0.161662223806132)) * 6.8231093058295) + 6.8231093058295)"},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_test.html","id":null,"dir":"Reference","previous_headings":"","what":"Tests base predict function against tidypredict — tidypredict_test","title":"Tests base predict function against tidypredict — tidypredict_test","text":"Compares results predict() tidypredict_to_column() functions.","code":""},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_test.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tests base predict function against tidypredict — tidypredict_test","text":"","code":"tidypredict_test( model, df = model$model, threshold = 1e-12, include_intervals = FALSE, max_rows = NULL, xg_df = NULL )"},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_test.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tests base predict function against tidypredict — tidypredict_test","text":"model R model list parsed model. currently supports lm(), glm() randomForest() models. df data frame contains needed fields run prediction. defaults \"model\" data frame object inside model object. threshold number given result difference, predict() tidypredict_to_column() exceed. continuous predictions, default value 0.000000000001 (1e-12), categorical predictions, default value 0. include_intervals Switch indicate prediction intervals included test. defaults FALSE. max_rows number rows object passed df argument. Highly recommended large data sets. xg_df xgb.DMatrix object, required XGBoost models. defaults NULL recommended large data sets.","code":""},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_test.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tests base predict function against tidypredict — tidypredict_test","text":"","code":"model <- lm(mpg ~ wt + cyl * disp, offset = am, data = mtcars) tidypredict_test(model) #> tidypredict test results #> Difference threshold: 1e-12 #> #> All results are within the difference threshold"},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_to_column.html","id":null,"dir":"Reference","previous_headings":"","what":"Adds the prediction columns to a piped command set. — tidypredict_to_column","title":"Adds the prediction columns to a piped command set. — tidypredict_to_column","text":"Adds new column results tidypredict_fit() piped command set. add_interval set TRUE, add two additional columns- one lower another upper prediction interval bounds.","code":""},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_to_column.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Adds the prediction columns to a piped command set. — tidypredict_to_column","text":"","code":"tidypredict_to_column( df, model, add_interval = FALSE, interval = 0.95, vars = c(\"fit\", \"upper\", \"lower\") )"},{"path":"https://tidypredict.tidymodels.org/reference/tidypredict_to_column.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Adds the prediction columns to a piped command set. — tidypredict_to_column","text":"df data.frame tibble model R model parsed model inside data frame add_interval Switch indicates prediction interval columns added. Defaults FALSE interval prediction interval, defaults 0.95. Ignored add_interval set FALSE vars name variables function produce. Defaults \"fit\", \"upper\", \"lower\".","code":""},{"path":[]},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"tidypredict-051","dir":"Changelog","previous_headings":"","what":"tidypredict 0.5.1","title":"tidypredict 0.5.1","text":"CRAN release: 2024-12-19 Exported number internal functions used {orbital} package","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"tidypredict-05","dir":"Changelog","previous_headings":"","what":"tidypredict 0.5","title":"tidypredict 0.5","text":"CRAN release: 2023-01-18 Changes maintainer Edgar Ruiz Updates author’s email addresses. Removes dependency stringr Fixes issue earth parsed_models (#108) Addresses issues XGBoost models Improvements XGBoosts tests","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"tidypredict-049","dir":"Changelog","previous_headings":"","what":"tidypredict 0.4.9","title":"tidypredict 0.4.9","text":"CRAN release: 2022-05-25 Fixes issue handling GLM Binomial earth models (#97) Adds capability handle single simple Cubist models (#57) Fixed parenthesis issue creation interval formula (#76) Fixed bug SQL query generation XGBoost models objective binary:logistic. Re-licensed package GPL-3 MIT. See consent copyright holders .","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"tidypredict-048","dir":"Changelog","previous_headings":"","what":"tidypredict 0.4.8","title":"tidypredict 0.4.8","text":"CRAN release: 2020-10-28 CRAN submission broken test case.","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"tidypredict-047","dir":"Changelog","previous_headings":"","what":"tidypredict 0.4.7","title":"tidypredict 0.4.7","text":"CRAN release: 2020-10-05 Change version 5.1.2 earth package. result, tidypredict parse objects created later versions earth.","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"tidypredict-046","dir":"Changelog","previous_headings":"","what":"tidypredict 0.4.6","title":"tidypredict 0.4.6","text":"CRAN release: 2020-07-23 Small release xgboost changes.","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"tidypredict-045","dir":"Changelog","previous_headings":"","what":"tidypredict 0.4.5","title":"tidypredict 0.4.5","text":"CRAN release: 2020-02-10 Switches maintainer Max Kuhn","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"tidypredict-043","dir":"Changelog","previous_headings":"","what":"tidypredict 0.4.3","title":"tidypredict 0.4.3","text":"CRAN release: 2019-09-03 Adds support categorical predictors partykit Fixes parsnip tests meet standards new CRAN version","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"tidypredict-042","dir":"Changelog","previous_headings":"","what":"tidypredict 0.4.2","title":"tidypredict 0.4.2","text":"CRAN release: 2019-07-15 Simplifies tests verify ranger Adds fit method parsed xgboost models Sets conditional requirement xgboost, test vignette","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"tidypredict-040","dir":"Changelog","previous_headings":"","what":"tidypredict 0.4.0","title":"tidypredict 0.4.0","text":"CRAN release: 2019-07-12","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"new-features-0-4-0","dir":"Changelog","previous_headings":"","what":"New features","title":"tidypredict 0.4.0","text":"Parses ranger classification models. Adds method support broom’s tidy() function. Regression models Adds as_parsed_model() function. adds proper class components list. Adds initial support partykit’s ctree() model Adds support parsnip fitted models: lm, randomForest, ranger, earth Adds support xgb.Booster models provided xgboost package (@Athospd, #43) Adds support Cubist::cubist() models (# 36)","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"tidypredict-030","dir":"Changelog","previous_headings":"","what":"tidypredict 0.3.0","title":"tidypredict 0.3.0","text":"CRAN release: 2019-01-10","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"new-features-0-3-0","dir":"Changelog","previous_headings":"","what":"New features","title":"tidypredict 0.3.0","text":"Adds support MARS models provided earth package","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"improvements-0-3-0","dir":"Changelog","previous_headings":"","what":"Improvements","title":"tidypredict 0.3.0","text":"New parsed models now list objects opposed data frames. tidypredict_to_column() longer supports ranger randomForest multiple queries generated multiple trees. functions read parsed models create tidy eval formula now use list object. code depends dplyr programming removed. Removes dependencies : tidyr, tibble x/y interface earth models can now used.","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"bug-fixes-0-3-0","dir":"Changelog","previous_headings":"","what":"Bug Fixes","title":"tidypredict 0.3.0","text":"now returns trees instead just one tree based models (randomForest & ranger) (#29)","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"tidypredict-021","dir":"Changelog","previous_headings":"","what":"tidypredict 0.2.1","title":"tidypredict 0.2.1","text":"CRAN release: 2018-12-20","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"bug-fixes-0-2-1","dir":"Changelog","previous_headings":"","what":"Bug Fixes","title":"tidypredict 0.2.1","text":"tibble 2.0.0 compatibility fix (@krlmlr)","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"tidypredict-020","dir":"Changelog","previous_headings":"","what":"tidypredict 0.2.0","title":"tidypredict 0.2.0","text":"CRAN release: 2018-02-25","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"new-features-0-2-0","dir":"Changelog","previous_headings":"","what":"New features","title":"tidypredict 0.2.0","text":"Add support ranger() models.","code":""},{"path":"https://tidypredict.tidymodels.org/news/index.html","id":"bug-fixes-0-2-0","dir":"Changelog","previous_headings":"","what":"Bug fixes","title":"tidypredict 0.2.0","text":"Using x ~. randomForest() formula fails (#18 @washcycle).","code":""}]