Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scaled MSE to regression evaluation metrics #297

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions R/commonMachineLearningRegression.R
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@
table$dependOn(options = c(.mlRegressionDependencies(options), "validationMeasures"))
table$addColumnInfo(name = "measures", title = "", type = "string")
table$addColumnInfo(name = "values", title = gettext("Value"), type = "string")
measures <- c("MSE", "RMSE", "MAE / MAD", "MAPE", "R\u00B2")
measures <- c("MSE", gettext("MSE(scaled)"), "RMSE", "MAE / MAD", "MAPE", "R\u00B2")
table[["measures"]] <- measures
jaspResults[["validationMeasures"]] <- table
if (!ready) {
Expand All @@ -495,11 +495,14 @@
obs <- predDat[["obs"]]
pred <- predDat[["pred"]]
mse <- round(regressionResult[["testMSE"]], 3)
obs_scaled <- (obs - mean(obs)) / sd(obs)
pred_scaled <- (pred - mean(pred)) / sd(pred)
mse_scaled <- round(mean((obs_scaled - pred_scaled)^2), 3)
rmse <- round(sqrt(mse), 3)
mae <- round(mean(abs(obs - pred)), 3)
mape <- paste0(round(mean(abs((obs - pred) / obs)) * 100, 2), "%")
r_squared <- round(cor(obs, pred)^2, 3)
values <- c(mse, rmse, mae, mape, r_squared)
values <- c(mse, mse_scaled, rmse, mae, mape, r_squared)
table[["values"]] <- values
if (is.na(r_squared)) {
table$addFootnote(gettextf("R%s cannot be computed due to lack of variance in the predictions.</i>", "\u00B2"))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-mlregressionboosting.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ test_that("Boosting Regression table results match", {
test_that("Evaluation Metrics table results match", {
table <- results[["results"]][["validationMeasures"]][["data"]]
jaspTools::expect_equal_tables(table,
list("MSE", 0.28, "RMSE", 0.529, "MAE / MAD", 0.425, "MAPE", "3.33%",
list("MSE", 0.28, "MSE(scaled)", 0.374, "RMSE", 0.529, "MAE / MAD", 0.425, "MAPE", "3.33%",
"R<unicode><unicode>", 0.652))
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-mlregressiondecisiontree.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ test_that("Additive Explanations for Predictions of Test Set Cases table results
test_that("Model Performance Metrics table results match", {
table <- results[["results"]][["validationMeasures"]][["data"]]
jaspTools::expect_equal_tables(table,
list("MSE", 0.18, "RMSE", 0.424, "MAE / MAD", 0.354, "MAPE", "6.01%",
list("MSE", 0.18, "MSE(scaled)", 0.349, "RMSE", 0.424, "MAE / MAD", 0.354, "MAPE", "6.01%",
"R<unicode>", 0.671))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-mlregressionknn.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ test_that("K-Nearest Neighbors Regression table results match", {
test_that("Model Performance Metrics table results match", {
table <- results[["results"]][["validationMeasures"]][["data"]]
jaspTools::expect_equal_tables(table,
list("MSE", 0.379, "RMSE", 0.616, "MAE / MAD", 0.512, "MAPE", "3.98%",
list("MSE", 0.379, "MSE(scaled)", 0.583, "RMSE", 0.616, "MAE / MAD", 0.512, "MAPE", "3.98%",
"R<unicode>", 0.49))
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-mlregressionlinear.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ test_that("Additive Explanations for Predictions of Test Set Cases table results
test_that("Model Performance Metrics table results match", {
table <- results[["results"]][["validationMeasures"]][["data"]]
jaspTools::expect_equal_tables(table,
list("MSE", 0.079, "RMSE", 0.281, "MAE / MAD", 0.228, "MAPE", "8.08%",
list("MSE", 0.079, "MSE(scaled)", 0.023, "RMSE", 0.281, "MAE / MAD", 0.228, "MAPE", "8.08%",
"R<unicode>", 0.976))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-mlregressionneuralnetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test_that("Neural Network Regression table results match", {
test_that("Model Performance Metrics table results match", {
table <- results[["results"]][["validationMeasures"]][["data"]]
jaspTools::expect_equal_tables(table,
list("MSE", 0.089, "RMSE", 0.298, "MAE / MAD", 0.243, "MAPE", "4.18%",
list("MSE", 0.089, "MSE(scaled)", 0.156, "RMSE", 0.298, "MAE / MAD", 0.243, "MAPE", "4.18%",
"R<unicode>", 0.845))
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-mlregressionrandomforest.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ test_that("Feature Importance Metrics table results match", {
test_that("Evaluation Metrics table results match", {
table <- results[["results"]][["validationMeasures"]][["data"]]
jaspTools::expect_equal_tables(table,
list("MSE", 0.355, "RMSE", 0.596, "MAE / MAD", 0.473, "MAPE", "3.71%",
list("MSE", 0.355, "MSE(scaled)", 0.531, "RMSE", 0.596, "MAE / MAD", 0.473, "MAPE", "3.71%",
"R<unicode><unicode>", 0.528))
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-mlregressionregularized.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ test_that("Regularized Linear Regression table results match", {
test_that("Model Performance Metrics table results match", {
table <- results[["results"]][["validationMeasures"]][["data"]]
jaspTools::expect_equal_tables(table,
list("MSE", 0.316, "RMSE", 0.562, "MAE / MAD", 0.428, "MAPE", "3.34%",
list("MSE", 0.316, "MSE(scaled)", 0.504, "RMSE", 0.562, "MAE / MAD", 0.428, "MAPE", "3.34%",
"R<unicode>", 0.549))
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-mlregressionsvm.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,6 @@ test_that("Additive Explanations for Predictions of Test Set Cases table results
test_that("Model Performance Metrics table results match", {
table <- results[["results"]][["validationMeasures"]][["data"]]
jaspTools::expect_equal_tables(table,
list("MSE", 0.079, "RMSE", 0.281, "MAE / MAD", 0.234, "MAPE", "4.05%",
list("MSE", 0.079, "MSE(scaled)", 0.149, "RMSE", 0.281, "MAE / MAD", 0.234, "MAPE", "4.05%",
"R<unicode>", 0.852))
})
Loading