Hi, I am brand new to Power BI and I keep getting this error when trying to create a barplot using the r script visualization tool: Error: unexpected symbol in: ""setwd(Sys.getenv('RScriptWrapperWorkingDirectory')) graphics.off" Execution halted. It seems to be something running in the background since I do not have this strand in my code segment. Here is the relevant portion of my code segment:
# Calculate evaluation metrics for the mean naive model
mean_naive_mae <- mean(abs(avg_predictions - test_data$target))
mean_naive_rmse <- sqrt(mean((avg_predictions - test_data$target)^2))
mean_naive_mape <- mean(abs((avg_predictions - test_data$target) / test_data$target)) * 100
mean_naive_ss_residual <- sum((test_data$target - avg_predictions)^2)
mean_naive_ss_total <- sum((test_data$target - mean(test_data$target))^2)
mean_naive_r_squared <- 1 - (mean_naive_ss_residual / mean_naive_ss_total)
# Custom formatting function
custom_format <- function(x) {
ifelse(x >= 1000, formatC(x, format = "d", big.mark = ",", digits = 0),
formatC(x, format = "f", big.mark = ",", digits = 4)
)
}
# Create a data frame with the evaluation metrics for your model, the naive model, and the mean naive model
# Read the evaluation metrics data
metrics <- data.frame(
Metric = c("MAE", "RMSE", "MAPE", "R-squared"),
Boosted_Model = c(mae, rmse, mape, r_squared),
Recent_Model = c(naive_mae, naive_rmse, naive_mape, naive_r_squared),
Average_Model = c(mean_naive_mae, mean_naive_rmse, mean_naive_mape, mean_naive_r_squared),
stringsAsFactors = FALSE
)
# Plot the evaluation metrics as a bar plot
barplot(as.matrix(metrics[, -1]), beside = TRUE, names.arg = metrics$Metric,
main = "Evaluation Metrics", xlab = "Metric", ylab = "Value",
Thanks!