tests/testthat/test_R_tree.R

library(testthat)
test_that("tests that RF is working", {
  
  context("RF tree")
  
  set.seed(1242)
  x <- iris[, -1]
  y <- iris[, 1]
  # Preprocess the data
  preprocessedData <- preprocess_training(x, y)
  processed_x <- preprocessedData$x
  categoricalFeatureCols <- preprocessedData$categoricalFeatureCols
  categoricalFeatureMapping <-
    preprocessedData$categoricalFeatureMapping

  tree <- RFTree(
    x = processed_x,
    y = y,
    mtry = 2,
    nodesize = 2,
    # sampleIndex = sampleIndex,
    # splitrule = splitrule,
    categoricalFeatureCol = categoricalFeatureCols
  )

  feature.new <- x
  # Preprocess the data
  processed_x <- preprocess_testing(feature.new,
                                    categoricalFeatureCols,
                                    categoricalFeatureMapping)
  expect_equal(
    predict(tree,
            processed_x,
            x,
            y,
            avgfunc = avgMean,
            categoricalFeatureCols)[1],
    5.266667,
    tolerance = 0.00001
  )
})
theo-s/Rforestry_R documentation built on Dec. 23, 2021, 9:55 a.m.