Description Usage Arguments Examples
Train random forest model on hyperspec object
1 2 3 4 5 6 7 8 9 10 |
hs.x |
Hyperspec object |
metadata |
Dataframe containing the categorical variable/group to predict (target_var) and also a column with the matching spectrum identifiers (spectrumID_col). |
target_var |
Categorical variable/group to predict in metadata |
spectrumID_col |
Column with the matching spectrum identifiers (spectrumID_col) in metadata |
ntree |
Number of trees to build. Defaults to 500. |
p_train |
Percentage of data to use in training model. Defaults to 0.75. |
metric |
Metric to use to report/maximize performance of model (only for method_ML = "rf") |
... |
additional parameters passed on to caret::train |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # Short example
data("hs_example")
# Preprocess
hs_example <- hs_preprocess(hs_example)
# Mock-up metadata
mock_meta <- data.frame(Spectrum_ID = rownames(hs_example@data$spc),
group = factor(c(rep(1,30),rep(2,34))))
# Calculate metrics
hs.RF <- hs_RF(hs.x = hs_example, metadata = mock_meta, spectrumID_col= "Spectrum_ID",
target_var = "group")
# Trained model
print(hs.RF[[1]])
# Confusion matrix
print(hs.RF[[2]])
# Variable importance metric
caret::varImp(hs.RF[[1]])
# Perform predictions
hs_RF_pred(hs.x = hs_example, model = hs.RF[[1]])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.