1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| library(caret)
annee <- 2000:2022
colonne1 <- runif(length(annee))
colonne2 <- runif(length(annee))
colonne3 <- runif(length(annee))
colonne4 <- runif(length(annee))
colonne5 <- runif(length(annee))
target <- runif(length(annee))
donnees <- data.frame(colonne1, colonne2, colonne3, colonne4, colonne5, target)
data_ts <- ts(donnees, start = 2000, end = 2022, frequency = 1)
train <- window(data_ts, start=2000, end=2021)
test <- window(data_ts, start=2022, end=2022)
val_reel <- as.numeric(test[, "target"])
test <- test[, c(setdiff(colnames(data_ts), "target"))]
train_x <- train[, c(setdiff(colnames(train), "target"))]
train_y <- train[, "target"][,1]
caret_model <- train(x=train_x, y=train_y, method="rf")
pred <- caret_model %>% predict(newdata = test) |
Partager