Skip to content

Commit 73d1786

Browse files
author
ercbk
committed
added outer fold score to msg in raschka, added stroke to bars
1 parent ce0b256 commit 73d1786

File tree

6 files changed

+24
-4
lines changed

6 files changed

+24
-4
lines changed

README.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ runs <- runs_raw %>%
6565
raschka <- runs %>%
6666
filter(method == "raschka") %>%
6767
ggplot(aes(y = duration, x = implementation, label = duration)) +
68-
geom_bar(stat = "identity", width = 0.50, fill = "#195198") +
68+
geom_bar(aes(color = after_scale(prismatic::clr_darken(rep("#195198",4), 0.3))), fill = "#195198", stat = "identity", width = 0.50) +
6969
coord_flip() +
7070
scale_x_reordered() +
7171
geom_text(hjust = 1.3, size = 3.5, color = "white") +
@@ -77,7 +77,7 @@ raschka <- runs %>%
7777
kj <- runs %>%
7878
filter(method == "kj") %>%
7979
ggplot(aes(y = duration, x = implementation, label = duration)) +
80-
geom_bar(stat = "identity", width = 0.50, fill = "#BD9865") +
80+
geom_bar(aes(color = after_scale(prismatic::clr_darken(rep("#BD9865",5), 0.3))), stat = "identity", width = 0.50, fill = "#BD9865") +
8181
coord_flip() +
8282
scale_x_reordered() +
8383
geom_text(hjust = 1.3, size = 3.5, color = "white") +
-307 Bytes
Loading

duration-experiment/raschka/nested-cv-kj-raschka.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ if (!is.data.frame(chosen_preds)) {
295295
}
296296
test_error <- round(error_FUN(test_dat$y, chosen_preds), 5)
297297

298+
# avg error across outer-loop folds in ncv
299+
outer_kfold_error <- algorithm_comparison %>%
300+
filter(model == chosen_alg) %>%
301+
mutate(mean_error = round(mean_error, 5)) %>%
302+
pull(mean_error)
298303

299304
# Create output message and text me the results
300305
best_hyper_vals <- best_hyper_vals %>%
@@ -303,6 +308,7 @@ best_hyper_vals <- best_hyper_vals %>%
303308
glue_collapse(sep = ",", last = " and ")
304309

305310
msg <- glue("Avg K-Fold CV error: {avg_kfold_error[[1]]}
311+
Outer-Fold Avg Error: {outer_kfold_error}
306312
Test Error: {test_error}
307313
Best Parameters for {chosen_alg}:
308314
{best_hyper_vals}")

duration-experiment/raschka/nested-cv-mlr3-raschka.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,15 @@ best_params <- as.data.frame(chosen_train$tuning_result$params) %>%
241241
glue_data("{param} = {value}") %>%
242242
glue_collapse(sep = ",", last = " and ")
243243

244+
# avg error across outer-loop folds in ncv
245+
outer_kfold_error <- algorithm_comparison %>%
246+
filter(model == chosen_alg) %>%
247+
mutate(mean_error = round(mean_error, 5)) %>%
248+
pull(mean_error)
249+
244250

245251
msg <- glue("Average of K-fold CV test folds: {kfold_error}
252+
Outer-Fold Avg Error: {outer_kfold_error}
246253
Training Error: {train_error}
247254
Test Error: {test_error}
248255
Best Parameters for {chosen_alg}:

duration-experiment/raschka/nested-cv-py-raschka.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,16 @@
267267

268268
# Average error across tuning folds and the parameter values chosen during tuning
269269
k_fold_score = round(-1 * gcv_model_select.best_score_, 5)
270+
outer_kfold_score = round(results[results.model == chosen_alg]['mean_error'][0], 5)
270271
best_hyper_vals = gcv_model_select.best_params_
271272

272273
# best_hyper_vals is a dict. Use it to create the df, then add the errors.
273274
model_stats = pd.DataFrame(data = best_hyper_vals, index = [1])
274-
model_stats = model_stats.assign(kfold_error = k_fold_score, train_error = train_error, test_error = test_error)
275+
model_stats = model_stats.assign(kfold_error = k_fold_score, outer_fold_error = outer_kfold_score, train_error = train_error, test_error = test_error)
275276

276277

277278
# evidently has to be written into a paragraph because print outputs can't be saved and there's no glue in python.
278-
msg = f'Python script finished in {time_elapsed} seconds. The chosen algorithm was {chosen_alg} with parameters, {best_hyper_vals}. Avg score over cv\'s test folds was {k_fold_score}. Training Error: {train_error}, Test Error: {test_error}'
279+
msg = f'Python script finished in {time_elapsed} seconds. The chosen algorithm was {chosen_alg} with parameters, {best_hyper_vals}. Avg score over cv\'s test folds was {k_fold_score}. Outer fold avg score was {outer_kfold_score}. Training Error: {train_error}, Test Error: {test_error}'
279280

280281
# text me the results
281282
pb.push_note("Nested CV script finished", msg)

duration-experiment/raschka/nested-cv-retic-raschka.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,14 @@ best_params <- as.data.frame(chosen_tuned$best_params_) %>%
301301
glue_data("{param} = {value}") %>%
302302
glue_collapse(sep = ",", last = " and ")
303303

304+
outer_kfold_error <- purrr::map_dfr(algorithm_comparison, ~select(., mean_error), .id = "model") %>%
305+
filter(mean_error == min(mean_error)) %>%
306+
mutate(mean_error = round(mean_error, 5))
307+
pull(mean_error)
308+
304309

305310
msg <- glue("Average of K-fold CV test folds: {kfold_error}
311+
Outer-Fold Avg Error: {outer_kfold_error}
306312
Training Error: {train_error}
307313
Test Error: {test_error}
308314
Best Parameters for {chosen_alg}:

0 commit comments

Comments
 (0)