-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.r
57 lines (46 loc) · 1.51 KB
/
server.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
49
50
51
52
53
54
55
56
57
# server.R
load('model.rda')
shinyServer(function(input, output) {
output$roc_plot <-
renderPlot({roc_plot})
output$predicted_diabetes <-
renderText({
features <- data.frame(
pregnant = input$pregnant,
glucose = input$glucose,
pressure = input$pressure,
triceps = input$triceps,
insulin = input$insulin,
mass = input$mass,
pedigree = input$pedigree,
age = input$age
)
print(features)
paste('Risk of diabetes:',
predict(model, features, type = "prob")[[2]])
})
output$explainer <-
renderPlot({
features <- data.frame(
pregnant = input$pregnant,
glucose = input$glucose,
pressure = input$pressure,
triceps = input$triceps,
insulin = input$insulin,
mass = input$mass,
pedigree = input$pedigree,
age = input$age
)
explainer <- lime(test.data, model, n_bins = 5)
explanation <- lime::explain(x = features,
explainer = explainer,
n_permutations = 5000,
dist_fun = 'gower',
kernel_width = .75,
n_features = 8,
feature_select = 'highest_weights',
labels = 'pos')
# explanation[, 2:9]
plot_features(explanation, ncol = 1)
})
})