The neural network models (model_07 and model_08) require the keras3 package. Follow these steps to install it:
If you're getting "unable to access index for repository" errors, first fix your CRAN mirror:
# Set a working CRAN mirror
options(repos = c(CRAN = "https://cloud.r-project.org"))
# Or choose a mirror interactively
chooseCRANmirror()# Install devtools or remotes (try both if one fails)
install.packages("devtools")
# OR
install.packages("remotes")# Using devtools
devtools::install_github("rstudio/keras3")
# OR using remotes
remotes::install_github("rstudio/keras3")install.packages("keras3")Note: If you're using R 4.4, keras3 might not be available on CRAN yet. Use Option A (GitHub) instead.
For easiest installation, run the provided script:
Rscript install_keras3.ROr in R:
source("install_keras3.R")After installing keras3, TensorFlow will be automatically installed when you first run:
library(keras3)
use_backend("tensorflow")This happens automatically when you run the neural network model scripts.
You can verify the installation by running:
library(keras3)
use_backend("tensorflow")
cat("Keras3 and TensorFlow are ready!\n")If you see "unable to access index for repository" errors:
# Set a working CRAN mirror
options(repos = c(CRAN = "https://cloud.r-project.org"))
# Then try installing againIf you see "package 'keras3' is not available for this version of R":
- keras3 might require R 4.5+ or need to be installed from GitHub
- Use the GitHub installation method:
devtools::install_github("rstudio/keras3")
-
Try installing from a different CRAN mirror:
options(repos = c(CRAN = "https://cloud.r-project.org")) install.packages("devtools")
-
Or download and install manually from:
- Make sure you have Python installed on your system
- Install reticulate package:
install.packages("reticulate") - Try installing TensorFlow manually:
library(reticulate) py_install("tensorflow")
- Make sure you've installed keras3 from GitHub successfully
- Check if the package is loaded:
library(keras3) - Try restarting R session and installing again
- Verify installation:
packageVersion("keras3")
If you don't need to run the neural network models, you can skip them and run only the other models:
- model_01_glm_lasso_min.R
- model_02_glm_lasso_1se.R
- model_03_random_forest.R
- model_04_ranger.R
- model_05_xgboost.R
- model_06_simple_glm.R
These models don't require keras3.