...
Code Block |
---|
library(ForestForesight) # Step 1: Set up the parameters parameters # Make sure you have DATA_FOLDER in config.yml in your working directory ff_environment has been run, otherwise assign ff_folder yourself # to the folder you used for ff_sync ff_folder <- Sys.getenv("DATAFF_FOLDER") country_code <- "PERSUR" train_start <- "2023-06-01" train_end <- "2023-1207-3101" validation_start <- "2023-0608-01" validation_end <- "2023-1208-01" prediction_date <- "2024-01-01" # Step 2: Create date ranges for training and validation validation train_dates <- ForestForesight::daterange(train_start, train_end) validation_dates <- ForestForesight::daterange(validation_start, validation_end) # Step 3: Set up file paths for saving results results model_save_path <- paste0(ff_folder, "peru_deforestation_model.model") predictions_save_path <- paste0(ff_folder, "peru_deforestation_prediction.tif") accuracy_csv_path <- paste0(ff_folder, "peru_deforestation_accuracy.csv") importance_csv_path <- paste(ff_folder, "peru_feature_importance.csv") # Step 4: Run the ff_run function function prediction_result <- ff_run( country = country_code, prediction_dates = prediction_date, ff_folder = ff_folder, train_dates = train_dates, validation_dates = TRUE, ff_train_parameters = list("nrounds" = validation_dates, 25), model_save_path = model_save_path, predictions_save_path_predictions = predictions_save_path, accuracy_output_csvpath = accuracy_csv_path, importance_output_csvpath = importance_csv_path, verbose = TRUE, autoscale_sample = TRUE FALSE ) # Step 5: Plot the prediction result if (!is.na(prediction_result)) { plot(prediction_resultresult$predictions, main = "Deforestation Prediction for PeruLaos") } # Step 6: Print a summary of the results results ff_cat("Prediction completed. Results saved to disk:\n") ff_cat("Model:", model_save_path, "\n") ff_cat("Prediction raster:", predictions_save_path, "\n") ff_cat("Accuracy CSV:", accuracy_csv_path, "\n") ff_cat("Feature importance CSV:", importance_csv_path, "\n") # Optional: Load and print the first few lines of the accuracy CSV if (file.exists(accuracy_csv_path)) { CSV accuracy_data <- read.csv(accuracy_csv_path) prediction_result$accuracy ff_cat("\nFirstFirst few lines of accuracy data:\n") print(head(accuracy_data)) } |
For more information about the config file please refer to the configuration page here Open-Source Contribution .
...