modeldb

library(dplyr)
library(modeldb)

R-CMD-check CRAN_Status_Badge Codecov test coverage Downloads

Fit models inside the database! modeldb works with most database back-ends because it leverages dplyr and dbplyr for the final SQL translation of the algorithm. It currently supports:

Installation

Install the CRAN version with:

install.packages("modeldb")

The development version is available from GitHub using remotes:

# install.packages("remotes")
remotes::install_github("tidymodels/modeldb")

Linear regression

An easy way to try out the package is by creating a temporary SQLite database, and loading mtcars to it.

con <- DBI::dbConnect(RSQLite::SQLite(), path = ":memory:")
RSQLite::initExtension(con)
dplyr::copy_to(con, mtcars)
library(dplyr)

tbl(con, "mtcars") %>%
  select(wt, mpg, qsec) %>%
  linear_regression_db(wt)

The model output can be parsed by tidypredict to run the predictions in the database. Please see the "Linear Regression" article to learn more about how to use linear_regression_db()

K Means clustering

To use the simple_kmeans_db() function, simply pipe the database back end table to the function. This returns a list object that contains two items:

km <- tbl(con, "mtcars") %>%
  simple_kmeans_db(mpg, wt)

colnames(km)

The SQL statement from tbl can be extracted using dbplyr's remote_query()

dbplyr::remote_query(km)

Contributing

This project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.



tidymodels/modeldb documentation built on Jan. 27, 2024, 8:42 a.m.