-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest server.R
31 lines (26 loc) · 1.12 KB
/
Test 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
server <- function(input, output, session) {
# Reactive function to predict churn based on user inputs
prediction <- eventReactive(input$predictBtn, {
new_data <- data.frame(
tenure = input$tenure,
Contract = factor(input$contractType, levels = levels(train_data$Contract)),
MonthlyCharges = input$monthlyCharges,
InternetService = factor(input$internetService, levels = levels(train_data$InternetService)),
OnlineSecurity = factor(input$onlineSecurity, levels = levels(train_data$OnlineSecurity))
)
# Generate prediction probability for the logistic regression model
prob <- predict(logistic_model, newdata = new_data, type = "response")
round(prob * 100, 2) # Return probability as a percentage
})
# Display Prediction Output
output$predictionOutput <- renderText({
paste("Predicted Churn Probability:", prediction(), "%")
})
# Display Model Summary
output$modelSummary <- renderPrint({
summary(logistic_model)
})
}
# Run the application
shinyApp(ui, server)
install.packages("plotly")