someone pls tell me what im doing wrong im so confused
title: "Random Forest Tutorial"
output: learnr::tutorial
runtime: shiny_prerendered
library(learnr)
library(shiny)
library(dplyr)
library(readr)
library(randomForest)
library(gradethis)
# Tutorial settings
tutorial_options(
exercise.timelimit = 60,
exercise.checker = gradethis::grade_learnr,
exercise.reveal_solution = FALSE
)
# Load training data
train_data <- read_csv("data/studentscores.csv")
# Train Random Forest model once
rf_model <- randomForest(average_scores ~ ., data = train_data, ntree = 100)
View the Random Forest Model
print(rf_model)
Create New Input for Prediction
new_data <- train_data[1, ]
new_data$math_score <- 88
new_data$chemistry_score <- 72
new_data$biology_score <- 90
new_data$english_score <- 85
new_data$history_score <- 78
new_data$math_score
Make a Prediction
new_data <- train_data[1, ]
new_data$math_score <- 88 # adjust values if needed
predicted_score <- round(predict(rf_model, newdata = new_data), 2)
predicted_score
Categorize the Predicted Grade
result <- if (predicted_score < 70) {
"Fail"
} else if (predicted_score < 85) {
"Pass"
} else {
"Excellent"
}
result
Display Final Result
cat("🎯 Your predicted grade is", predicted_score, "—", result, "\n")
Full Final Test
new_data <- train_data[1, ]
new_data$english_score <- 100
new_data$chemistry_score <- 64
new_data$biology_score <- 95
new_data$math_score <- 85
predicted_score <- round(predict(rf_model, newdata = new_data), 2)
result <- if (predicted_score < 70) {
"Fail"
} else if (predicted_score < 85) {
"Pass"
} else {
"Excellent"
}
cat("🎯 Your predicted grade is", predicted_score, "—", result, "\n")