在网状结构中找不到sklearn(LocalOutlierFactor)的私有函数 [英] Can't find private function for sklearn (LocalOutlierFactor) in reticulate
问题描述
我试图将python代码的一部分添加到我的R脚本中.不幸的是,我似乎无法为R中的LocalOutlierFactor使用私有函数:
I tried to add a part of a python code to my R Script. Unfortunately it seems that I can't use a private function for the LocalOutlierFactor in R:
# Sample Data
n <- 5000
n_outlier <- .05 * n
set.seed(11212)
inlier <- mvtnorm::rmvnorm(n, mean = c(0,0))
outlier <- mvtnorm::rmvnorm(n_outlier, mean = c(20, 20))
testdata <- rbind(inlier, outlier)
smp_size <- floor(0.5 * nrow(testdata))
train_ind <- sample(seq_len(nrow(testdata)), size = smp_size)
train_lof <-as.data.frame(testdata[train_ind, ])
test_lof <- as.data.frame(testdata[-train_ind, ])
sklearn.neighbors <- import("sklearn.neighbors")
lof1 <- sklearn.neighbors$LocalOutlierFactor(n_neighbors=15)
lof1$fit(train_lof)
现在,我想借助LocalOutlierFactor的私有功能_decision_function
预测test_lof
:
Now I want to predict for test_lof
with help of the private function _decision_function
from LocalOutlierFactor:
lof1$_decision_function(test_lof)
不幸的是,使用网状结构时没有这样的功能(在Python中是可用的).有谁知道如何使用网状结构的私有函数,可以为我提供帮助吗?提前致谢.
Unfortunately there is not such a function available when using reticulate (in Python the function is there). Does anyone know how to use private functions from reticulate and can help me? Thanks in advance.
推荐答案
您可以使用[[
访问这些字段/功能. lof1[['_decision_function']]
应该给您您想要的.
You can use [[
to access those fields/functions. lof1[['_decision_function']]
should give you what you want.
这篇关于在网状结构中找不到sklearn(LocalOutlierFactor)的私有函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!