【发布时间】:2021-09-25 22:10:15
【问题描述】:
我正在尝试从 R 中的 Tensorflow 实现自动编码器降维,在此示例中:
library(dimRed)
library(tensorflow)
fraud_data <- read.csv("fraud_data")
data_label <- fraud_data["class"]
my_formula <- as.formula("class ~ .")
dat <- as.dimRedData(my_formula, fraud_data)
dimen <- NULL
dimension_params <- NULL
dimen <- dimRed::AutoEncoder()
dimension_params <- dimen@stdpars
dimension_params$ndim <- 2
emb <- dimen@fun(fraud_data, dimension_params)
dimensional_data <- data.frame(emb@data@data)
x11()
plot(x=dimensional_data[,1], y=dimensional_data[,2], col=data_label, main="Laplacian Eigenmaps Projection")
legend(x=legend_pos, legend = unique(data_label), col=unique(data_label), pch=1)
我不断收到AttributeError module 'tensorflow' has no attribute 'placeholder'”,如此回溯中所述:
14. stop(structure(list(message = "AttributeError: module 'tensorflow' has no attribute 'placeholder'",
call = py_get_attr_impl(x, name, silent), cppstack = NULL), class = c("Rcpp::exception",
"C++Error", "error", "condition")))
13. py_get_attr_impl(x, name, silent)
12. py_get_attr(x, name)
11. py_get_attr_or_item(x, name, TRUE)
10. `$.python.builtin.object`(x, name)
9. `$.python.builtin.module`(tf, "placeholder")
8. tf$placeholder
7. graph_params(d_in = ncol(indata), n_hidden = n_hidden, activation = activation,
weight_decay = weight_decay, learning_rate = learning_rate,
n_steps = n_steps, ndim = ndim)
6. eval(substitute(expr), data, enclos = parent.frame())
5. eval(substitute(expr), data, enclos = parent.frame())
4. with.default(pars, {
graph_params(d_in = ncol(indata), n_hidden = n_hidden, activation = activation,
weight_decay = weight_decay, learning_rate = learning_rate,
n_steps = n_steps, ndim = ndim) ...
3. with(pars, {
graph_params(d_in = ncol(indata), n_hidden = n_hidden, activation = activation,
weight_decay = weight_decay, learning_rate = learning_rate,
n_steps = n_steps, ndim = ndim) ...
2. dimen@fun(dat, dimension_params)
Error in py_get_attr_impl(x, name, silent) :
AttributeError: module 'tensorflow' has no attribute 'placeholder'
由于常见的解决方案是按照Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session' 中的说明禁用 Tensorflow 2 行为,因此我尝试使用 reticulate 并通过此示例抑制错误:
library(reticulate)
x <- import("tensorflow.compat.v1", as="tf")
x$disable_v2_behavior()
但这并没有改变任何东西..我仍然得到AttributeError,我想知道,在这种情况下,我应该如何从 R 中对 Tensorflow 进行适当的更改?
这里是用于示例的示例数据:https://drive.google.com/file/d/1Yt4V1Ir00fm1vQ9futziWbwjUE9VvYK7/view?usp=sharing
【问题讨论】:
标签: r tensorflow autoencoder