Run Predictions Inside the Database

It parses a fitted 'R' model object, and returns a formula in 'Tidy Eval' code that calculates the predictions. It works with several databases back-ends because it leverages 'dplyr' and 'dbplyr' for the final 'SQL' translation of the algorithm. It currently supports lm(), glm(), randomForest(), ranger() and earth() models.


BuildStatus CRAN_Status_Badge CoverageStatus

Downloads

Run predictions inside the database. tidypredict parses a fitted R model object, and returns a formula in ‘Tidy Eval’ code that calculates the predictions.

It works with several databases back-ends because it leverages dplyr and dbplyr for the final SQL translation of the algorithm. It currently supports lm(), glm(), randomForest(), ranger() ane earth() models.

Installation

Install tidypredict from CRAN using:

install.packages("tidypredict")

Or install the development version using devtools as follows:

devtools::install_github("edgararuiz/tidypredict")

Intro

tidypredict is able to parse an R model object, such as:

model <- lm(mpg ~ wt + cyl, data = mtcars)

And then creates the SQL statement needed to calculate the fitted prediction:

tidypredict_sql(model, dbplyr::simulate_mssql())
## <SQL> 39.6862614802529 + (`wt` * -3.19097213898374) + (`cyl` * -1.5077949682598)

Supported models

The following models are supported:

  • Linear Regression - lm()
  • Generalized Linear model - glm()
  • Random Forest models - randomForest::randomForest()
  • Random Forest models, via ranger - ranger::ranger()
  • MARS models - earth::earth()

News

tidypredict 0.3.0

New features

  • Adds support for MARS models provided by the earth package

Improvements

  • New parsed models are now list objects as opposed to data frames.

  • tidypredict_to_column() no longer supports ranger and randomForest because of the multiple queries generated by multiple trees.

  • All functions that read the parsed models and create the tidy eval formula now use the list object.

  • Most of the code that depends on dplyr programming has been removed.

  • Removes dependencies on: tidyr, tibble

Bug Fixes

  • It now returns all of the trees instead of just one for tree based models (randomForest & ranger) (#29)

tidypredict 0.2.1

Bug Fixes

  • tibble 2.0.0 compatability fix (@krlmlr)

tidypredict 0.2.0

New features

  • Add support for ranger() models.

Bug fixes

  • Using x ~. in a randomForest() formula fails (#18 @washcycle).

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("tidypredict")

0.3.0 by Edgar Ruiz, 5 months ago


http://tidypredict.netlify.com/


Report a bug at https://github.com/edgararuiz/tidypredict/issues


Browse source code at https://github.com/cran/tidypredict


Authors: Edgar Ruiz [aut, cre]


Documentation:   PDF Manual  


Task views: Model Deployment with R


GPL-3 license


Imports dplyr, rlang, purrr, knitr

Suggests dbplyr, testthat, randomForest, ranger, earth, rmarkdown, nycflights13, RSQLite, methods, DBI, covr


Imported by tidymodels.


See at CRAN