项目作者: MaximilianPi

项目描述 :
Machine learning algorithms to infer trait‐matching and predict species interactions in ecological networks.
高级语言: R
项目地址: git://github.com/MaximilianPi/TraitMatching.git
创建时间: 2020-10-03T11:14:50Z
项目社区:https://github.com/MaximilianPi/TraitMatching

开源协议:

下载


R-CMD-check
Project Status: Active – The project has reached a stable, usable state and is being actively developed.
License: GPL v3

TraitMatching package

This is a new implementation of the TraitMatching (see https://github.com/TheoreticalEcology/Pichler-et-al-2019 ) package based on mlr3.

More about using machine learning for TraitMatching: https://doi.org/10.1111/2041-210X.13329

To install the package:

  1. devtools::install_github(repo = "https://github.com/MaximilianPi/TraitMatching", subdir = "TraitMatching")
  2. library(TraitMatching)

Workflow

1) simulate data (replace the A, B, and Z matrices with your own):

  1. library(TraitMatching)
  1. ## Warning: replacing previous import 'mlr3measures::tnr' by 'mlr3tuning::tnr' when
  2. ## loading 'TraitMatching'
  1. sim = simulateInteraction(weights = list(main = 0.1, inter = c(0.3,0.3,0.3)))
  2. A = sim$A
  3. B = sim$B
  4. Z = sim$binar()
  5. community = createCommunity(A, B, Z)
  1. ## missForest iteration 1 in progress...done!
  2. ## missForest iteration 2 in progress...done!
  3. ## missForest iteration 1 in progress...done!
  4. ## missForest iteration 2 in progress...done!

2) Fit random forest in a nested resampling strategy and with hyper-parameter tuning:

  1. result = runTM(community = community, method = "RF", iters = 20L)
  1. print(result)
  1. ## nr resample_result task_id learner_id resampling_id
  2. ## 1: 1 <ResampleResult[21]> classif_community classif.ranger.tuned custom
  3. ## iters classif.auc
  4. ## 1: 10 0.705656

3) Compare different ML algorithms:

  1. result = runTM(community = community, method = c("RF", "SVM"), iters = 3L)
  1. print(result)
  1. ## nr resample_result task_id learner_id resampling_id
  2. ## 1: 1 <ResampleResult[21]> classif_community classif.ranger.tuned custom
  3. ## 2: 2 <ResampleResult[21]> classif_community classif.svm.tuned custom
  4. ## iters classif.auc
  5. ## 1: 10 0.7127029
  6. ## 2: 10 0.5529854

4) Predict target for new data with different ensemble ML algorithms (trained with optimal hyper-parameters)

  1. predict(result, newdata=community$data[1:5,])
  1. ## RF SVM
  2. ## 1 0.8869743 0.7538086
  3. ## 2 0.9247219 0.8050551
  4. ## 3 0.5959860 0.5702086
  5. ## 4 0.7903801 0.5801098
  6. ## 5 0.4514330 0.3647977