@@ -12,9 +12,9 @@ back-ends** because it leverages [dplyr](https://dplyr.tidyverse.org/)
12
12
and [ dbplyr] ( https://dbplyr.tidyverse.org/ ) for the final SQL
13
13
translation of the algorithm. It currently supports:
14
14
15
- - K-means clustering
15
+ - K-means clustering
16
16
17
- - Linear regression
17
+ - Linear regression
18
18
19
19
## Installation
20
20
@@ -66,8 +66,8 @@ To use the `simple_kmeans_db()` function, simply pipe the database back
66
66
end table to the function. This returns a list object that contains two
67
67
items:
68
68
69
- - A sql query table with the final center assignment
70
- - A local table with the information about the centers
69
+ - A sql query table with the final center assignment
70
+ - A local table with the information about the centers
71
71
72
72
``` r
73
73
km <- tbl(con , " mtcars" ) %> %
@@ -87,52 +87,101 @@ The SQL statement from `tbl` can be extracted using dbplyr’s
87
87
dbplyr :: remote_query(km )
88
88
```
89
89
90
- ## <SQL> SELECT `k_center`, `k_mpg`, `k_wt`, `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`
91
- ## FROM (SELECT `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`, `LHS`.`k_center` AS `k_center`, `k_mpg`, `k_wt`
92
- ## FROM (SELECT `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`, `center` AS `k_center`
93
- ## FROM (SELECT `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`, `center_1`, `center_2`, `center_3`, CASE
94
- ## WHEN (`center_1` >= `center_1` AND `center_1` < `center_2` AND `center_1` < `center_3`) THEN ('center_1')
95
- ## WHEN (`center_2` < `center_1` AND `center_2` >= `center_2` AND `center_2` < `center_3`) THEN ('center_2')
96
- ## WHEN (`center_3` < `center_1` AND `center_3` < `center_2` AND `center_3` >= `center_3`) THEN ('center_3')
90
+ ## <SQL> SELECT
91
+ ## `LHS`.`k_center` AS `k_center`,
92
+ ## `k_mpg`,
93
+ ## `k_wt`,
94
+ ## `mpg`,
95
+ ## `cyl`,
96
+ ## `disp`,
97
+ ## `hp`,
98
+ ## `drat`,
99
+ ## `wt`,
100
+ ## `qsec`,
101
+ ## `vs`,
102
+ ## `am`,
103
+ ## `gear`,
104
+ ## `carb`
105
+ ## FROM (
106
+ ## SELECT
107
+ ## `mpg`,
108
+ ## `cyl`,
109
+ ## `disp`,
110
+ ## `hp`,
111
+ ## `drat`,
112
+ ## `wt`,
113
+ ## `qsec`,
114
+ ## `vs`,
115
+ ## `am`,
116
+ ## `gear`,
117
+ ## `carb`,
118
+ ## `center` AS `k_center`
119
+ ## FROM (
120
+ ## SELECT
121
+ ## `q01`.*,
122
+ ## CASE
123
+ ## WHEN (`center_1` >= `center_1` AND `center_1` < `center_2` AND `center_1` < `center_3`) THEN 'center_1'
124
+ ## WHEN (`center_2` < `center_1` AND `center_2` >= `center_2` AND `center_2` < `center_3`) THEN 'center_2'
125
+ ## WHEN (`center_3` < `center_1` AND `center_3` < `center_2` AND `center_3` >= `center_3`) THEN 'center_3'
97
126
## END AS `center`
98
- ## 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`
99
- ## FROM `mtcars`))
100
- ## WHERE (NOT(((`center`) IS NULL)))) AS `LHS`
101
- ## LEFT JOIN (SELECT `center` AS `k_center`, `mpg` AS `k_mpg`, `wt` AS `k_wt`
102
- ## FROM (SELECT `center`, AVG(`mpg`) AS `mpg`, AVG(`wt`) AS `wt`
103
- ## FROM (SELECT `mpg`, `wt`, `center`
104
- ## FROM (SELECT `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`, `center_1`, `center_2`, `center_3`, CASE
105
- ## WHEN (`center_1` >= `center_1` AND `center_1` < `center_2` AND `center_1` < `center_3`) THEN ('center_1')
106
- ## WHEN (`center_2` < `center_1` AND `center_2` >= `center_2` AND `center_2` < `center_3`) THEN ('center_2')
107
- ## WHEN (`center_3` < `center_1` AND `center_3` < `center_2` AND `center_3` >= `center_3`) THEN ('center_3')
127
+ ## FROM (
128
+ ## SELECT
129
+ ## `mtcars`.*,
130
+ ## SQRT(((20.6428571428571 - `mpg`) * (20.6428571428571 - `mpg`)) + ((3.07214285714286 - `wt`) * (3.07214285714286 - `wt`))) AS `center_1`,
131
+ ## SQRT(((14.4583333333333 - `mpg`) * (14.4583333333333 - `mpg`)) + ((4.05866666666667 - `wt`) * (4.05866666666667 - `wt`))) AS `center_2`,
132
+ ## SQRT(((30.0666666666667 - `mpg`) * (30.0666666666667 - `mpg`)) + ((1.873 - `wt`) * (1.873 - `wt`))) AS `center_3`
133
+ ## FROM `mtcars`
134
+ ## ) AS `q01`
135
+ ## ) AS `q01`
136
+ ## WHERE (NOT((`center` IS NULL)))
137
+ ## ) AS `LHS`
138
+ ## LEFT JOIN (
139
+ ## SELECT `center` AS `k_center`, AVG(`mpg`) AS `k_mpg`, AVG(`wt`) AS `k_wt`
140
+ ## FROM (
141
+ ## SELECT `mpg`, `wt`, `center`
142
+ ## FROM (
143
+ ## SELECT
144
+ ## `q01`.*,
145
+ ## CASE
146
+ ## WHEN (`center_1` >= `center_1` AND `center_1` < `center_2` AND `center_1` < `center_3`) THEN 'center_1'
147
+ ## WHEN (`center_2` < `center_1` AND `center_2` >= `center_2` AND `center_2` < `center_3`) THEN 'center_2'
148
+ ## WHEN (`center_3` < `center_1` AND `center_3` < `center_2` AND `center_3` >= `center_3`) THEN 'center_3'
108
149
## END AS `center`
109
- ## 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`
110
- ## FROM `mtcars`))
111
- ## WHERE (NOT(((`center`) IS NULL))))
112
- ## GROUP BY `center`)) AS `RHS`
113
- ## ON (`LHS`.`k_center` = `RHS`.`k_center`)
114
- ## )
150
+ ## FROM (
151
+ ## SELECT
152
+ ## `mtcars`.*,
153
+ ## SQRT(((20.6428571428571 - `mpg`) * (20.6428571428571 - `mpg`)) + ((3.07214285714286 - `wt`) * (3.07214285714286 - `wt`))) AS `center_1`,
154
+ ## SQRT(((14.4583333333333 - `mpg`) * (14.4583333333333 - `mpg`)) + ((4.05866666666667 - `wt`) * (4.05866666666667 - `wt`))) AS `center_2`,
155
+ ## SQRT(((30.0666666666667 - `mpg`) * (30.0666666666667 - `mpg`)) + ((1.873 - `wt`) * (1.873 - `wt`))) AS `center_3`
156
+ ## FROM `mtcars`
157
+ ## ) AS `q01`
158
+ ## ) AS `q01`
159
+ ## WHERE (NOT((`center` IS NULL)))
160
+ ## ) AS `q01`
161
+ ## GROUP BY `center`
162
+ ## ) AS `RHS`
163
+ ## ON (`LHS`.`k_center` = `RHS`.`k_center`)
115
164
116
165
## Contributing
117
166
118
167
This project is released with a [ Contributor Code of
119
168
Conduct] ( https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html ) .
120
169
By contributing to this project, you agree to abide by its terms.
121
170
122
- - For questions and discussions about tidymodels packages, modeling,
123
- and machine learning, please [ post on Posit
124
- Community] ( https://community.rstudio.com /new-topic?category_id=15&tags=tidymodels,question ) .
171
+ - For questions and discussions about tidymodels packages, modeling, and
172
+ machine learning, please [ post on Posit
173
+ Community] ( https://forum.posit.co /new-topic?category_id=15&tags=tidymodels,question ) .
125
174
126
- - If you think you have encountered a bug, please [ submit an
127
- issue] ( https://github.com/tidymodels/modeldb/issues ) .
175
+ - If you think you have encountered a bug, please [ submit an
176
+ issue] ( https://github.com/tidymodels/modeldb/issues ) .
128
177
129
- - Either way, learn how to create and share a
130
- [ reprex] ( https://reprex.tidyverse.org/articles/articles/learn-reprex.html )
131
- (a minimal, reproducible example), to clearly communicate about your
132
- code. Check out [ this helpful article on how to create
133
- reprexes] ( https://dbplyr.tidyverse.org/articles/reprex.html ) for
134
- problems involving a database.
178
+ - Either way, learn how to create and share a
179
+ [ reprex] ( https://reprex.tidyverse.org/articles/articles/learn-reprex.html )
180
+ (a minimal, reproducible example), to clearly communicate about your
181
+ code. Check out [ this helpful article on how to create
182
+ reprexes] ( https://dbplyr.tidyverse.org/articles/reprex.html ) for
183
+ problems involving a database.
135
184
136
- - Check out further details on [ contributing guidelines for tidymodels
137
- packages] ( https://www.tidymodels.org/contribute/ ) and [ how to get
138
- help] ( https://www.tidymodels.org/help/ ) .
185
+ - Check out further details on [ contributing guidelines for tidymodels
186
+ packages] ( https://www.tidymodels.org/contribute/ ) and [ how to get
187
+ help] ( https://www.tidymodels.org/help/ ) .
0 commit comments