This repository was archived by the owner on Dec 12, 2023. It is now read-only.
generated from course-files/BBT4206-Lab15of15-ConsumePlumberAPIOutput
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlumberAPI.R
More file actions
59 lines (48 loc) · 1.86 KB
/
PlumberAPI.R
File metadata and controls
59 lines (48 loc) · 1.86 KB
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
58
# Load required packages
if (require("plumber")) {
require("plumber")
} else {
install.packages("plumber", dependencies = TRUE,
repos = "https://cloud.r-project.org")
}
# Load required packages
library(randomForest)
library(plumber)
# Load your saved Random Forest model
loaded_random_forest_model <- readRDS("./models/saved_random_forest_model.rds")
# Define the Plumber API endpoint for your model
# This assumes your Random Forest model is used for disease prediction
#* @apiTitle Disease Prediction Model API
#* @apiDescription Used to predict the disease based on symptoms.
#* @param Symptom_1 Value for Symptom 1
#* @param Symptom_2 Value for Symptom 2
#* @param Symptom_3 Value for Symptom 3
#* @param Symptom_4 Value for Symptom 4
#* @param Symptom_5 Value for Symptom 5
#* @param Symptom_6 Value for Symptom 6
#* @param Symptom_7 Value for Symptom 7
#* @param Symptom_8 Value for Symptom 8
#* @get /predict_disease
predict_disease <- function(Symptom_1, Symptom_2, Symptom_3, Symptom_4,
Symptom_5, Symptom_6, Symptom_7, Symptom_8) {
# Create a data frame using the input symptoms
input_data <- data.frame(
Symptom_1 = as.numeric(Symptom_1),
Symptom_2 = as.numeric(Symptom_2),
Symptom_3 = as.numeric(Symptom_3),
Symptom_4 = as.numeric(Symptom_4),
Symptom_5 = as.numeric(Symptom_5),
Symptom_6 = as.numeric(Symptom_6),
Symptom_7 = as.numeric(Symptom_7),
Symptom_8 = as.numeric(Symptom_8)
)
# Make a prediction based on the input data using the loaded Random Forest model
predictions <- predict(loaded_random_forest_model, input_data)
return(predictions)
}
# Create a Plumber API object
#plumber_api <- plumber::plumber()
# Mount the endpoint to the plumber API
#plumber_api$mount("/my_model", predict_disease)
# Run the API
#plumber_api$run(port = 8000) # Change port number as needed