我按照这个示例操作:
https://www.2021.ai/randsharkmachinelearning/
在R中运行以下命令时:
sharkFit <- SharkRFTrain(X, Y, nTrees = 100)
我得到:
Error in SharkRFTrain(X, Y, nTrees = 100) : Should not call this. Fix the random numbers generator if you need this. 478
这个异常是从以下”cpp”行抛出的:
trainer.train(model, trainData);
我怀疑原因在这里:
https://github.com/aydindemircioglu/RcppShark#notes
随机数生成器已被替换,因为R包必须使用R的随机生成器而不是C/C++内部的。 因此,不能直接比较依赖(伪)随机数的算法结果。
有办法缓解这个问题吗?
我尝试了R的两个版本: 3.4.1, 3.3.2
回答:
我已经调查了这个问题,并在一定程度上缩小了范围:
- 错误消息在这里产生: https://github.com/aydindemircioglu/RcppShark/blob/master/src/shark/Rng/Runif.h#L71
- 调用代码在这里: https://github.com/aydindemircioglu/RcppShark/blob/master/src/src/Algorithms/RFTrainer.cpp#L178
由于我无法修复它,我在这里开了个问题: https://github.com/aydindemircioglu/RcppShark/issues/1