Skip to content

SQL predictions from linear models

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

assuncaolfi/qlm

Repository files navigation

qlm

Lifecycle: experimental CRAN status

qlm is a package to create SQL queries to compute predictions from linear models.

Installation

Install the development version of qlm:

devtools::install_github("assuncaolfi/qlm")

Example

Fit a model:

library(qlm)

data(iris)
iris <- janitor::clean_names(iris)
iris$large_sepal <- iris$sepal_length > median(iris$sepal_length)

model <- glm(
  large_sepal ~ sepal_width + petal_length + species, 
  data = iris, 
  family = binomial("logit")
)

Make a predictive query:

query <- qlm(model, inverse_link = "1 / (1 + EXP(-{x}))")
cat(query)
#> WITH 
#> effects AS (
#>   SELECT 
#>       1 * -32.2006 AS intercept,
#>       sepal_width * 0.9066 AS sepal_width,
#>       petal_length * 5.5194 AS petal_length,
#>       CAST(species = 'versicolor' AS INT) * 6.0682 AS is_species_versicolor,
#>       CAST(species = 'virginica' AS INT) * 2.9912 AS is_species_virginica
#>   FROM iris
#> ),
#> linear AS (
#>   SELECT 
#>       intercept +
#>       sepal_width +
#>       petal_length +
#>       is_species_versicolor +
#>       is_species_virginica
#>     AS prediction
#>   FROM effects
#> )
#> SELECT 1 / (1 + EXP(-prediction)) AS prediction
#> FROM linear

Formula interactions and transformations are not supported and should be precomputed in the data query.

About

SQL predictions from linear models

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages