Can't find private function for sklearn (LocalOutlierFactor) in reticulate

ぃ、小莉子 提交于 2019-12-24 12:03:17

问题


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)

Now I want to predict for test_lof with help of the private function _decision_function from LocalOutlierFactor:

lof1$_decision_function(test_lof)

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.


回答1:


You can use [[ to access those fields/functions. lof1[['_decision_function']] should give you what you want.



来源:https://stackoverflow.com/questions/50289232/cant-find-private-function-for-sklearn-localoutlierfactor-in-reticulate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!