Skip to content

Commit 3ed7d7e

Browse files
Jingjing TangJingjing Tang
authored andcommitted
change the cols saved in output files
1 parent 8ce7082 commit 3ed7d7e

File tree

2 files changed

+17
-4
lines changed
  • backfill_corrections/delphiBackfillCorrection/R

2 files changed

+17
-4
lines changed

backfill_corrections/delphiBackfillCorrection/R/io.R

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,30 @@ export_test_result <- function(test_data, coef_data, indicator, signal,
3838
geo=geo, value_type=value_type, model_mode=FALSE)
3939

4040
signal_info <- str_interp("indicator ${indicator} signal ${signal} geo ${geo} value_type ${value_type}")
41+
42+
components <- c(indicator, signal, signal_suffix)
43+
signal_dir = paste0(
44+
# Drop any empty strings.
45+
paste(components[components != ""], collapse="_"),
46+
)
47+
4148
if (nrow(test_data) == 0) {
4249
warning(str_interp("No test data available for ${signal_info}"))
4350
} else {
4451
msg_ts(str_interp("Saving predictions to disk for ${signal_info} "))
4552
pred_output_file <- str_interp("prediction_${base_name}")
46-
write_csv(test_data, file.path(export_dir, pred_output_file))
53+
54+
prediction_col <- colnames(test_data)[grepl("^predicted", colnames(test_data))]
55+
expected_col <- c("time_value", "issue_date", "lag", "target_date", "wis", prediction_col)
56+
write_csv(test_data[expected_col], file.path(export_dir, signal_dir, pred_output_file))
4757
}
4858

4959
if (nrow(coef_data) == 0) {
5060
warning(str_interp("No coef data available for ${signal_info}"))
5161
} else {
5262
msg_ts(str_interp("Saving coefficients to disk for ${signal_info}"))
53-
coef_output_file <- str_interp("coefs_${base_name}")
54-
write_csv(coef_data, file.path(export_dir, coef_output_file))
63+
coef_output_file <- str_interp("coefs_${base_name}")
64+
write_csv(coef_data, file.path(export_dir, signal_dir, coef_output_file))
5565
}
5666
}
5767

backfill_corrections/delphiBackfillCorrection/R/model.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ model_training_and_testing <- function(train_data, test_data, taus, covariates,
136136
if (success < length(taus)) {return (NULL)}
137137
if (!make_predictions) {return (list())}
138138

139-
coef_combined_result = data.frame(tau=taus, geo=geo, test_lag=test_lag)
139+
coef_combined_result = data.frame(tau=taus, geo=geo, test_lag=test_lag,
140+
training_end_date=training_end_date,
141+
training_start_date=training_start_date,
142+
lambda=lambda)
140143
coef_combined_result[coef_list] = as.matrix(do.call(rbind, coefs_result))
141144

142145
return (list(test_data, coef_combined_result))

0 commit comments

Comments
 (0)