{"metadata":{"kernelspec":{"name":"ir","display_name":"R","language":"R"},"language_info":{"name":"R","codemirror_mode":"r","pygments_lexer":"r","mimetype":"text/x-r-source","file_extension":".r","version":"4.0.5"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"This is a starter notebook which allows the use of R in the competition through the reticulate package. Many of the ideas come from the notebook created here (https://www.kaggle.com/dmitriyguller/r-starter-notebook-with-15x-faster-prediction-loop) for the NFL Big Data Bowl competition.","metadata":{}},{"cell_type":"code","source":"library(tidyverse)\nlibrary(reticulate)\nlibrary(tibble)\nlibrary(data.table)\n\noptions(scipen = 999)\n\ngresearch_crypto <- import_from_path('competition','../input/g-research-crypto-forecasting/gresearch_crypto')\n\nenv <- gresearch_crypto$make_env()\niter <- env$iter_test()\n\npy_run_string(\"import io\")\npy_run_string(\"import pandas\")","metadata":{"_uuid":"051d70d956493feee0c6d64651c6a088724dca2a","_execution_state":"idle","execution":{"iopub.status.busy":"2021-11-03T14:23:58.257795Z","iopub.execute_input":"2021-11-03T14:23:58.259870Z","iopub.status.idle":"2021-11-03T14:24:03.865449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"This placeholder function should be modified to actually generate meaningful predictions.","metadata":{}},{"cell_type":"code","source":"generate_predictions <- function(test_df){\n    return(runif(nrow(test_df), 0, 1))\n}","metadata":{"execution":{"iopub.status.busy":"2021-11-03T14:24:04.182033Z","iopub.execute_input":"2021-11-03T14:24:04.225583Z","iopub.status.idle":"2021-11-03T14:24:04.256562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"This is the main loop. It iterates over the test set and generates predictions.","metadata":{}},{"cell_type":"code","source":"i <- 0\n\nwhile(TRUE){\n    df <- iter_next(iter)\n    if (is.null(df)) break\n    \n    test_df <- fread(df[[1]]$to_csv(index = FALSE), data.table = FALSE)\n    pred_df <- fread(df[[2]]$to_csv(index = FALSE), data.table = FALSE)\n    \n    pred_df$Target <- generate_predictions(test_df)\n    \n    py$pred_df_string <- format_csv(pred_df)\n    py_run_string(\"pred_df = pandas.read_csv(io.StringIO(pred_df_string))\")\n    py_run_string(paste0(\"pred_df.index.values[0] = \", i))\n    pred_df_pointer <- py_get_attr(py, \"pred_df\")\n    \n    env$predict(pred_df_pointer)\n    \n    i <- i + 1\n}","metadata":{"execution":{"iopub.status.busy":"2021-11-03T14:24:07.516047Z","iopub.execute_input":"2021-11-03T14:24:07.518088Z","iopub.status.idle":"2021-11-03T14:24:07.753295Z"},"trusted":true},"execution_count":null,"outputs":[]}]}