-
Notifications
You must be signed in to change notification settings - Fork 2
/
plumber.R
48 lines (44 loc) · 925 Bytes
/
plumber.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
library(jsonlite)
mod <- readRDS("model.RDS")
# dat <- readRDS("testx.RDS")
#* predict diamond price
#*
#* @param new_data new data
#* @get /predict
function(new_data) {
one_row <- as.data.frame(jsonlite::fromJSON(new_data))
return(
list(
price = predict.lm(mod, newdata = one_row)
)
)
}
#* Predict a diamond price given separate values
#* @param carat
#* @param cut
#* @param color
#* @param clarity
#* @param depth
#* @param table
#* @param x
#* @param y
#* @param z
#* @get /predict2
function(carat, cut, color, clarity, depth, table, x, y, z) {
dat <- data.frame(
carat = as.numeric(carat),
cut = as.character(cut),
color = as.character(color),
clarity = as.character(clarity),
depth = as.numeric(depth),
table = as.numeric(table),
x = as.numeric(x),
y = as.numeric(y),
z = as.numeric(z)
)
return(
list(
price = predict.lm(mod, dat)
)
)
}