r2pmml Error in .convert(tempfile, file, converter, converter_classpath, verbose) : 1 - r

I want to convert r neural network model into pmml, using r2pmml package based on jpmml:
mynn <- nnet(Churn ~ ., data=trainNN, size=3, decay=1.0e-5, maxit=50, softmax = TRUE)
r2pmml(mynn,"churn_nnet_pmml.xml")
But I have such error:
Jul 11, 2018 10:18:48 AM org.jpmml.rexp.Main run
INFO: Converting..
Jul 11, 2018 10:18:48 AM org.jpmml.rexp.Main run
SEVERE: Failed to convert
java.lang.IllegalArgumentException: nmatrix.2
at org.jpmml.rexp.RExpUtil.getDataType(RExpUtil.java:46)
at org.jpmml.rexp.FormulaUtil.createFormula(FormulaUtil.java:71)
at org.jpmml.rexp.NNetConverter.encodeSchema(NNetConverter.java:59)
at org.jpmml.rexp.ModelConverter.encodePMML(ModelConverter.java:69)
at org.jpmml.rexp.Converter.encodePMML(Converter.java:39)
at org.jpmml.rexp.Main.run(Main.java:149)
at org.jpmml.rexp.Main.main(Main.java:97)
Exception in thread "main" java.lang.IllegalArgumentException: nmatrix.2
at org.jpmml.rexp.RExpUtil.getDataType(RExpUtil.java:46)
at org.jpmml.rexp.FormulaUtil.createFormula(FormulaUtil.java:71)
at org.jpmml.rexp.NNetConverter.encodeSchema(NNetConverter.java:59)
at org.jpmml.rexp.ModelConverter.encodePMML(ModelConverter.java:69)
at org.jpmml.rexp.Converter.encodePMML(Converter.java:39)
at org.jpmml.rexp.Main.run(Main.java:149)
at org.jpmml.rexp.Main.main(Main.java:97)
Error in .convert(tempfile, file, converter, converter_classpath, verbose) :
1
As explained on https://github.com/jpmml/r2pmml/issues/28 this is a minor bug in the JPMML-R library.
I tried suggested workaround (to generate a fully populated variable.levels attribute manually):
mynn$variable.levels <- lapply(trainNN, function(x){ if(is.factor(x)){ levels(x) } else { NULL }})
And run with verbose option and added variable.levels:
r2pmml(mynn,"churn_nnet_pmml.xml", verbose = TRUE, variable.levels = mynn$variable.levels)
But then I have an error:
Error in decorate.default(x, ...) :
unused argument (variable.levels = list(X.area.code.408 = NULL,
X.area.code.510 = NULL, X.international.plan.1 = NULL, X.voice.mail.plan.1 =
NULL, X.total.eve.charge. = NULL, X.total.night.charge. = NULL,
X.total.intl.charge. = NULL, Churn = NULL))
So how to cope with that issue with r2pmml?
Thanks

Related

How to solve R future error "error in future$uuid : object of type closure is not subsettable"

When trying to register a future with a parallel backend in R, I receive the following error message:
Error in future$uuid : object of type 'closure' is not subsettable
Previously using future has always been fine.
My code:
# Previously installed future, doFuture, parallel and doParallel packages
library(future)
library(doFuture)
registerDoFuture()
no.clusters = max(detectCores()-4,1)
cl = parallel::makeCluster(no.clusters)
plan(cluster, workers = cl)
The error occurs when running the plan command. Restarting RStudio solves the issue for one run, but running the code a second time in the same session causes the error. Obviously, I'd prefer not having to restart RStudio and import all the data etc. every time I want to use the parallel programming, so help would be appreciated
Traceback:
16: FutureCondition(message = message, call = call, uuid = uuid,
future = future)
15: FutureError(sprintf("Cannot resolve %s (%s), because the connection to the worker is corrupt: %s",
class(x)[1], label, attr(isValid, "reason", exact = TRUE)),
future = future)
14: stop(FutureError(sprintf("Cannot resolve %s (%s), because the connection to the worker is corrupt: %s",
class(x)[1], label, attr(isValid, "reason", exact = TRUE)),
future = future))
13: resolved.ClusterFuture(future, run = FALSE)
12: resolved(future, run = FALSE)
11: collectValues(where, futures = futures, firstOnly = TRUE)
10: FutureRegistry(reg, action = "collect-first", earlySignal = TRUE)
9: await()
8: requestNode(await = function() {
FutureRegistry(reg, action = "collect-first", earlySignal = TRUE)
}, workers = workers)
7: run.ClusterFuture(future)
6: run(future)
5: strategy(..., envir = envir, workers = workers)
4: evaluator(NA, label = "future-plan-test", globals = FALSE, lazy = FALSE)
3: plan_init()
2: plan_set(newStack, skip = .skip, cleanup = .cleanup, init = .init)
1: plan(cluster, workers = cl)

R Error in py_get_attr_impl(x, name, silent) : AttributeError: module 'tensorflow' has no attribute 'placeholder'

I am trying to Implement Auto Encoder Dimension Reduction from Tensorflow in R, in this example:
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)
I keep getting AttributeError module 'tensorflow' has no attribute 'placeholder'" as stated in this traceback:
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'
As by the common solution is to Disable Tensorflow 2 Behaviour as stated in Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session', I tried to use reticulate and suppress the errors by this example:
library(reticulate)
x <- import("tensorflow.compat.v1", as="tf")
x$disable_v2_behavior()
but this doesn't change anything.. and I still get AttributeError, I am wondering, How should I make a proper change in Tensorflow from R in this case?
Here is Sample Data used for the example: https://drive.google.com/file/d/1Yt4V1Ir00fm1vQ9futziWbwjUE9VvYK7/view?usp=sharing
I found out deeper that tf acts as R tensorflow module, since ?tf is a valid command after using library(tensorflow), and then since Tensorflow updated to version 2+, instead using tf$placeholder, use tf$compat$v1$placeholder, so I had an idea to add the features available in tf$compat$v1 to tf
tf_synchronize <- function(){
library(tensorflow)
rm(list=c("tf")) #Delete first if there any tf variable in Global Environment
tf_compat_names <- names(tf$compat$v1)
for(x in 2:length(tf_compat_names)){
tf[[tf_compat_names[x]]] <- tf$compat$v1[[tf_compat_names[x]]]
}
}
With this executed, the AttributeError are no more, and Auto Encoder from Dimension Reduction is successfully executed

How to fix Error in CellChat <- netEmbedding(cellchat, type = "functional") / UMAP Problems?

This is regarding "Manifold and Classification learning analysis of signalling networks" in the [full tutorial/vignette][1].
I installed umap and it seems to run fine like this:
[Installing UMAP, a Python Package occurs successfully][2]
library(reticulate)
use_python("/Users/soumyasharma/opt/anaconda3/bin/python")
UMAP<-import("umap", convert = FALSE)
This command: cellchat <- computeNetSimilarity(cellchat, type = "functional") also seems to run well.
However: at the following command there is an error as displayed in the screenshot.
```library("CellChat") #https://github.com/sqjin/CellChat
cellchat <- netEmbedding(cellchat, type = "functional")```
[screenshot of error seen][3]
9.
stop(structure(list(message = "AttributeError: module 'umap' has no attribute 'UMAP'", call = py_get_attr_impl(x, name, silent), cppstack = structure(list( file = "", line = -1L, stack = c("1 reticulate.so 0x0000000112ee105e _ZN4Rcpp9exceptionC2EPKcb + 222", "2 reticulate.so 0x0000000112ee96a5 _ZN4Rcpp4stopERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE + 53", ...
8.
py_get_attr_impl(x, name, silent)
7.
py_get_attr(x, name)
6.
py_get_attr_or_item(x, name, TRUE)
5.
`$.python.builtin.object`(x, name)
4.
`$.python.builtin.module`(umap_import, "UMAP")
3.
umap_import$UMAP
2.
runUMAP(Similarity, min.dist = 0.3, n.neighbors = k)
1.
netEmbedding(cellchat, type = "functional")```
Can you please help me troubleshoot this?
[1]: https://htmlpreview.github.io/?https://github.com/sqjin/CellChat/blob/master/tutorial/CellChat-vignette.html
[2]: https://i.stack.imgur.com/QjLqT.png
[3]: https://i.stack.imgur.com/uoar6.png

error with earth function using MARS algo

I run my ML algo:
EarthAlgo<-earth(cible~., data=train, degree=4, glm=list(family=binomial))
I got:
Error in leaps.setup(x = bx, y = y, force.in = 1, force.out = NULL, intercept = FALSE, :
NA/NaN/Inf in foreign function call (arg 3)
When I try with train<-train[(1:dim(train)[1]-2),], it's ok. I search last two line on my train data set but i do not see error.
Could you help me please?

Trouble using the r package (random)

I want to generate random string and have installed the random package.
However, I couldn't run my code and received this error:
Error in url(urltxt, ..., method = "libcurl") : cannot open connection
In addition: Warning message: In url(urltxt, ..., method = "libcurl")
: URL 'https://www.random.org/strings/?num=7&len=6&digits=on&upperalpha=on&loweralpha=off&unique=on&format=plain&rnd=new'
: status was 'SSL connect error'
Here's my code:
library("random")
String<-randomStrings(n=7, len = 6, digits = TRUE, upperalpha = TRUE, loweralpha = FALSE, unique = TRUE, check = FALSE)
Anybody knows what's the source of this error?

Resources