【发布时间】:2025-12-02 16:00:02
【问题描述】:
我正在尝试了解使用 R 包 kernlab 中的命令 ksvm 时 SVM 预测函数的工作原理。
我尝试使用以下命令查看预测函数:
methods(class="ksvm")
getAnywhere(ksvm:::predict)
但是,我得到以下输出,而不是完整的预测函数:
A single object matching ‘:::’ ‘ksvm’ ‘predict’ was found
It was found in the following places
package:base
namespace:base
with value
function (pkg, name)
{
pkg <- as.character(substitute(pkg))
name <- as.character(substitute(name))
get(name, envir = asNamespace(pkg), inherits = FALSE)
}
<bytecode: 0x00000000088be4f8>
<environment: namespace:base>
Warning message:
In find(x, numeric = TRUE) :
elements of 'what' after the first will be ignored
谁能帮忙获取完整的预测函数?
更新 1:
mispelled 的建议在 kernlab 包中的 ksvm 预测函数上运行良好,但似乎不适用于 e1071 包中的 svm。
它会抛出以下错误:
> getMethod("predict", "svm")
Error in getMethod("predict", "svm") :
no generic function found for 'predict'
一般来说,如何知道使用哪种get方法?
【问题讨论】: