Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: modeldb
Title: Fits Models Inside the Database
Version: 0.3.0.9000
Version: 0.3.1
Authors@R: c(
person("Edgar", "Ruiz", , "[email protected]", role = "aut"),
person("Max", "Kuhn", , "[email protected]", role = c("aut", "cre"))
Expand Down Expand Up @@ -38,4 +38,4 @@ Config/Needs/website: tidyverse/tidytemplate
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# modeldb (development version)
# modeldb 0.3.1

- Fixes compatability issues with `ggplot2`

# modeldb 0.3.0

Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ dbplyr::remote_query(km)

This project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.

- For questions and discussions about tidymodels packages, modeling, and machine learning, please [post on Posit Community](https://community.rstudio.com/new-topic?category_id=15&tags=tidymodels,question).
- For questions and discussions about tidymodels packages, modeling, and machine learning, please [post on Posit Community](https://forum.posit.co/new-topic?category_id=15&tags=tidymodels,question).

- If you think you have encountered a bug, please [submit an issue](https://github.com/tidymodels/modeldb/issues).

Expand Down
131 changes: 90 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ back-ends** because it leverages [dplyr](https://dplyr.tidyverse.org/)
and [dbplyr](https://dbplyr.tidyverse.org/) for the final SQL
translation of the algorithm. It currently supports:

- K-means clustering
- K-means clustering

- Linear regression
- Linear regression

## Installation

Expand Down Expand Up @@ -66,8 +66,8 @@ 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:

- A sql query table with the final center assignment
- A local table with the information about the centers
- A sql query table with the final center assignment
- A local table with the information about the centers

``` r
km <- tbl(con, "mtcars") %>%
Expand All @@ -87,52 +87,101 @@ The SQL statement from `tbl` can be extracted using dbplyr’s
dbplyr::remote_query(km)
```

## <SQL> SELECT `k_center`, `k_mpg`, `k_wt`, `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`
## FROM (SELECT `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`, `LHS`.`k_center` AS `k_center`, `k_mpg`, `k_wt`
## FROM (SELECT `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`, `center` AS `k_center`
## FROM (SELECT `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`, `center_1`, `center_2`, `center_3`, CASE
## WHEN (`center_1` >= `center_1` AND `center_1` < `center_2` AND `center_1` < `center_3`) THEN ('center_1')
## WHEN (`center_2` < `center_1` AND `center_2` >= `center_2` AND `center_2` < `center_3`) THEN ('center_2')
## WHEN (`center_3` < `center_1` AND `center_3` < `center_2` AND `center_3` >= `center_3`) THEN ('center_3')
## <SQL> SELECT
## `LHS`.`k_center` AS `k_center`,
## `k_mpg`,
## `k_wt`,
## `mpg`,
## `cyl`,
## `disp`,
## `hp`,
## `drat`,
## `wt`,
## `qsec`,
## `vs`,
## `am`,
## `gear`,
## `carb`
## FROM (
## SELECT
## `mpg`,
## `cyl`,
## `disp`,
## `hp`,
## `drat`,
## `wt`,
## `qsec`,
## `vs`,
## `am`,
## `gear`,
## `carb`,
## `center` AS `k_center`
## FROM (
## SELECT
## `q01`.*,
## CASE
## WHEN (`center_1` >= `center_1` AND `center_1` < `center_2` AND `center_1` < `center_3`) THEN 'center_1'
## WHEN (`center_2` < `center_1` AND `center_2` >= `center_2` AND `center_2` < `center_3`) THEN 'center_2'
## WHEN (`center_3` < `center_1` AND `center_3` < `center_2` AND `center_3` >= `center_3`) THEN 'center_3'
## END AS `center`
## FROM (SELECT `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`, SQRT(((20.6428571428571 - `mpg`) * (20.6428571428571 - `mpg`)) + ((3.07214285714286 - `wt`) * (3.07214285714286 - `wt`))) AS `center_1`, SQRT(((14.4583333333333 - `mpg`) * (14.4583333333333 - `mpg`)) + ((4.05866666666667 - `wt`) * (4.05866666666667 - `wt`))) AS `center_2`, SQRT(((30.0666666666667 - `mpg`) * (30.0666666666667 - `mpg`)) + ((1.873 - `wt`) * (1.873 - `wt`))) AS `center_3`
## FROM `mtcars`))
## WHERE (NOT(((`center`) IS NULL)))) AS `LHS`
## LEFT JOIN (SELECT `center` AS `k_center`, `mpg` AS `k_mpg`, `wt` AS `k_wt`
## FROM (SELECT `center`, AVG(`mpg`) AS `mpg`, AVG(`wt`) AS `wt`
## FROM (SELECT `mpg`, `wt`, `center`
## FROM (SELECT `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`, `center_1`, `center_2`, `center_3`, CASE
## WHEN (`center_1` >= `center_1` AND `center_1` < `center_2` AND `center_1` < `center_3`) THEN ('center_1')
## WHEN (`center_2` < `center_1` AND `center_2` >= `center_2` AND `center_2` < `center_3`) THEN ('center_2')
## WHEN (`center_3` < `center_1` AND `center_3` < `center_2` AND `center_3` >= `center_3`) THEN ('center_3')
## FROM (
## SELECT
## `mtcars`.*,
## SQRT(((20.6428571428571 - `mpg`) * (20.6428571428571 - `mpg`)) + ((3.07214285714286 - `wt`) * (3.07214285714286 - `wt`))) AS `center_1`,
## SQRT(((14.4583333333333 - `mpg`) * (14.4583333333333 - `mpg`)) + ((4.05866666666667 - `wt`) * (4.05866666666667 - `wt`))) AS `center_2`,
## SQRT(((30.0666666666667 - `mpg`) * (30.0666666666667 - `mpg`)) + ((1.873 - `wt`) * (1.873 - `wt`))) AS `center_3`
## FROM `mtcars`
## ) AS `q01`
## ) AS `q01`
## WHERE (NOT((`center` IS NULL)))
## ) AS `LHS`
## LEFT JOIN (
## SELECT `center` AS `k_center`, AVG(`mpg`) AS `k_mpg`, AVG(`wt`) AS `k_wt`
## FROM (
## SELECT `mpg`, `wt`, `center`
## FROM (
## SELECT
## `q01`.*,
## CASE
## WHEN (`center_1` >= `center_1` AND `center_1` < `center_2` AND `center_1` < `center_3`) THEN 'center_1'
## WHEN (`center_2` < `center_1` AND `center_2` >= `center_2` AND `center_2` < `center_3`) THEN 'center_2'
## WHEN (`center_3` < `center_1` AND `center_3` < `center_2` AND `center_3` >= `center_3`) THEN 'center_3'
## END AS `center`
## FROM (SELECT `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`, SQRT(((20.6428571428571 - `mpg`) * (20.6428571428571 - `mpg`)) + ((3.07214285714286 - `wt`) * (3.07214285714286 - `wt`))) AS `center_1`, SQRT(((14.4583333333333 - `mpg`) * (14.4583333333333 - `mpg`)) + ((4.05866666666667 - `wt`) * (4.05866666666667 - `wt`))) AS `center_2`, SQRT(((30.0666666666667 - `mpg`) * (30.0666666666667 - `mpg`)) + ((1.873 - `wt`) * (1.873 - `wt`))) AS `center_3`
## FROM `mtcars`))
## WHERE (NOT(((`center`) IS NULL))))
## GROUP BY `center`)) AS `RHS`
## ON (`LHS`.`k_center` = `RHS`.`k_center`)
## )
## FROM (
## SELECT
## `mtcars`.*,
## SQRT(((20.6428571428571 - `mpg`) * (20.6428571428571 - `mpg`)) + ((3.07214285714286 - `wt`) * (3.07214285714286 - `wt`))) AS `center_1`,
## SQRT(((14.4583333333333 - `mpg`) * (14.4583333333333 - `mpg`)) + ((4.05866666666667 - `wt`) * (4.05866666666667 - `wt`))) AS `center_2`,
## SQRT(((30.0666666666667 - `mpg`) * (30.0666666666667 - `mpg`)) + ((1.873 - `wt`) * (1.873 - `wt`))) AS `center_3`
## FROM `mtcars`
## ) AS `q01`
## ) AS `q01`
## WHERE (NOT((`center` IS NULL)))
## ) AS `q01`
## GROUP BY `center`
## ) AS `RHS`
## ON (`LHS`.`k_center` = `RHS`.`k_center`)

## Contributing

This project is released with a [Contributor Code of
Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms.

- For questions and discussions about tidymodels packages, modeling,
and machine learning, please [post on Posit
Community](https://community.rstudio.com/new-topic?category_id=15&tags=tidymodels,question).
- For questions and discussions about tidymodels packages, modeling, and
machine learning, please [post on Posit
Community](https://forum.posit.co/new-topic?category_id=15&tags=tidymodels,question).

- If you think you have encountered a bug, please [submit an
issue](https://github.com/tidymodels/modeldb/issues).
- If you think you have encountered a bug, please [submit an
issue](https://github.com/tidymodels/modeldb/issues).

- Either way, learn how to create and share a
[reprex](https://reprex.tidyverse.org/articles/articles/learn-reprex.html)
(a minimal, reproducible example), to clearly communicate about your
code. Check out [this helpful article on how to create
reprexes](https://dbplyr.tidyverse.org/articles/reprex.html) for
problems involving a database.
- Either way, learn how to create and share a
[reprex](https://reprex.tidyverse.org/articles/articles/learn-reprex.html)
(a minimal, reproducible example), to clearly communicate about your
code. Check out [this helpful article on how to create
reprexes](https://dbplyr.tidyverse.org/articles/reprex.html) for
problems involving a database.

- Check out further details on [contributing guidelines for tidymodels
packages](https://www.tidymodels.org/contribute/) and [how to get
help](https://www.tidymodels.org/help/).
- Check out further details on [contributing guidelines for tidymodels
packages](https://www.tidymodels.org/contribute/) and [how to get
help](https://www.tidymodels.org/help/).
5 changes: 5 additions & 0 deletions man/modeldb-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions tests/testthat/test-as-parsed-model.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("parsed model")

test_that("Simple linear regression matches lm()", {
expect_is(
as_parsed_model(
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test_dummy_var.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("add_dummy_variables")

test_that("Function create the correct columns", {
cols_expected <- c("mpg", "disp", "hp", "drat", "wt", "qsec", "vs", "am", "gear", "carb", "cyl_6", "cyl_8")
expect_equal(
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test_kmeans.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("kmeans")

test_that("Specifying variables works", {
expect_is(
simple_kmeans_db(mtcars, wt, mpg),
Expand Down
7 changes: 2 additions & 5 deletions tests/testthat/test_kmeans_viz.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
context("kmeans_viz")


test_that("plot_kmeans() returns a ggplot2 object", {
expect_equal(
class(plot_kmeans(mtcars, mpg, wt, group = am)),
c("gg", "ggplot")
expect_true(
inherits(plot_kmeans(mtcars, mpg, wt, group = am), "ggplot")
)
})

Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test_lr.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("Linear Regression")

test_that("Simple linear regression matches lm()", {
expect_equal(
lm(wt ~ mpg, data = mtcars) %>%
Expand Down
Loading