Using meta learning in RWeka - java

I used RWeka to call Weka functions directly in R.
I tried using meta learning (bagging) but failed.
My code is Bagging(classLabel ~ ., data = train, control = Weka_control(W = J48))
However, the following error pops up:
Error in Bagging(classLabel ~ ., data = train, control = Weka_control(W = J48)) :
unused argument(s) (data = train, control = Weka_control(W = J48))
I also tried several different base learners but always met such error.
If you successfully used meta learning in RWeka before, please let me know.

Just tried another writing:
optns <- Weka_control(W = "weka.classifiers.trees.REPTree") Bagging <- make_Weka_classifier("weka/classifiers/meta/Bagging") model <- Bagging(classLabel ~ ., data=dat, control = optns)
Surprisingly the R code works now.
-Credit Leo5188

Related

R code in Java working in Linux but not in Windows

What am I doing?
I am writing a data analysis program in Java which relies on R´s arulesViz library to mine association rules.
What do I want?
My purpose is to store the rules in a String variable in Java so that I can process them later.
How does it work?
The code works using a combination of String.format and eval Java and RJava instructions respectively, being its behavior summarized as:
Given properly formatted Java data structures, creates a data frame in R.
Formats the recently created data frame into a transaction list using the arules library.
Runs the apriori algorithm with the transaction list and some necessary values passed as parameter.
Reorders the generated association rules.
Given that the association rules cannot be printed, they are written to the standard output with R´s write method, capture the output and store it in a variable. We have converted the association rules into a string variable.
We return the string.
The code is the following:
// Step 1
Rutils.rengine.eval("dataFrame <- data.frame(as.factor(c(\"Red\", \"Blue\", \"Yellow\", \"Blue\", \"Yellow\")), as.factor(c(\"Big\", \"Small\", \"Small\", \"Big\", \"Tiny\")), as.factor(c(\"Heavy\", \"Light\", \"Light\", \"Heavy\", \"Heavy\")))");
//Step 2
Rutils.rengine.eval("transList <- as(dataFrame, 'transactions')");
//Step 3
Rutils.rengine.eval(String.format("info <- apriori(transList, parameter = list(supp = %f, conf = %f, maxlen = 2))", supportThreshold, confidenceThreshold));
// Step 4
Rutils.rengine.eval("orderedRules <- sort(info, by = c('count', 'lift'), order = FALSE)");
// Step 5
REXP res = Rutils.rengine.eval("rulesAsString <- paste(capture.output(write(orderedRules, file = stdout(), sep = ',', quote = TRUE, row.names = FALSE, col.names = FALSE)), collapse='\n')");
// Step 6
return res.asString().replaceAll("'", "");
What´s wrong?
Running the code in Linux Will work perfectly, but when I try to run it in Windows, I get the following error referring to the return line:
Exception in thread "main" java.lang.NullPointerException
This is a common error I have whenever the R code generates a null result and passes it to Java. There´s no way to syntax check the R code inside Java, so whenever it´s wrong, this error message appears.
However, when I run the R code in brackets in the R command line in Windows, it works flawlessly, so both the syntax and the data flow are OK.
Technical information
In Linux, I am using R with OpenJDK 10.
In Windows, I am currently using Oracle´s latest JDK release, but trying to run the program with OpenJDK 12 for Windows does not solve anything.
Everything is 64 bits.
The IDE used in both operating systems is IntelliJ IDEA 2019.
Screenshots
Linux run configuration:
Windows run configuration:

not enough java heap space' r programming

I am out of my R depth. I defined a function nGrams (using RWeka) that worked fine when I tried it out, and sometimes it still does. I do not know how to figure out what environment it works in, what environment I am in when I want to use it, etc. Any quick tips or can you point me to a webpage that could help? If I have to put in a change environment command every time I use it, that is just fine. I really do not understand the issue.
here is what I see in my console.
blog2gramfreq <- nGrams(cleanblogs100000, 2)
Error in ls(envir = envir, all.names = private) :
invalid 'envir' argument
Called from: top level
Called from: top level
Browse[1]>
structure(function (this, private = FALSE, ...)
{
envir <- attr(this, ".env")
ls(envir = envir, all.names = private)
}, export = FALSE, S3class = "Object", modifiers = "public")
I do see nGrams in my Global Environment window.
This was something that came up in a Coursera class blog that i did not find an answer to, at least for R. Here is an answer that worked for me when I received the "'OutOfMemoryError : not enough java heap space" error in R programming.
options(java.parameters="-Xmx4000m")

JavaImp plugin not able to parse Java files

I have been using the JavaImp.vim script for auto importing Java statements in VIM
But trying out different directories in the JavaImpPaths, I am still unable to make JavaImp parse the Java files in the source to make auto imports possible
this is how my .vimrc looks like
let g:JavaImpPaths = "~/Documents/android-sdks/sources/android-21/android/content/"
let g:JavaImpClassList = "~/.vim/JavaImp/JavaImp.txt"
let g:JavaImpJarCache = "~/.vim/JavaImp/cache/"
This is what I get running JIG in new Vim window
:JIG
Do you want to create the directory ~/.vim/JavaImp/cache/?
Searching in path (package): ~/Documents/android-sdks/sources/android-21/android
/content/ ()
Sorting the classes, this may take a while ...
Assuring uniqueness...
Error detected while processing function <SNR>10_JavaImpGenerate:
line 75:
E37: No write since last change (add ! to override)
Done. Found 1 classes (0 unique)
Press ENTER or type command to continue
It might be late, but if anyone else comes along this might help them...
I got it working with the following changes to the script:
line 181 from
close
to
close!
And lines 207/208 from
let l:javaList = glob(a:cpath . "/**/*.java", 1, 1)
let l:clssList = glob(a:cpath . "/**/*.class", 1, 1)
to
let l:javaList = split(glob(a:cpath . "/**/*.java"), "\n")
let l:clssList = split(glob(a:cpath . "/**/*.class"), "\n")

Delphi XE5 - Android - Save file in server windows (shared folder)

Good morning,
I developed an application on Android through the Delphi XE5 which tries to save a text file in a shared folder on the server (windows) but I received the message I / O error 30. I've tried several ways in Assign File as describe in the code. Could help?
function gravar_registro():integer;
var NomeArqTxt: TextFile;
begin
try
begin
// AssignFile(NomeArqTxt, '/storage/sdcard1/FolderTEST/xxx.txt'); // Test1 OK = This is possible = OK = SDCARD
// AssignFile(NomeArqTxt, '/sdcard/FolderTEST/gerados/xxx.txt'); // Test2 OK = This is possible = OK = memória interna;
// AssignFile(NomeArqTxt, '\\192.168.1.152\FolderSHARED\xxx.txt'); // Test3 = ERROR = I've done testing, but I / O error 30
// AssignFile(NomeArqTxt, 'smb://192.168.1.152/FolderSHARED/xxx.txt'); // Test4 = ERROR = I've done testing, but I / O error 30
// AssignFile(NomeArqTxt, '192.168.1.152\FolderSHARED\xxx.txt'); // Test5 = ERROR = I've done testing, but I / O error 30
//. Observation: a) I've done testing with FolderSHARED folder and it has access to read / write
// b) The IP 192.168.1.152 is valid and active a personal computer on the internal network
{$I-}
Reset(NomeArqTxt);
{$I+}
if (IOResult <> 0) then
ReWrite(NomeArqTxt)
else
begin
CloseFile(NomeArqTxt);
Append(NomeArqTxt);
end;
Writeln(NomeArqTxt, 'TEST TEST TEST');
CloseFile(NomeArqTxt);
showmessage('File Saved...');
end
except
On Erro: Exception Do
begin
showmessage(Erro.Message);
end;
end;
end;
Use the TStringList object and then use it's TStringList.SaveToFile() function.
This is not possible without support for the network protocol used on the server side. For Windows, there is an Android library to support the SMB protocol. Some questions on Stackoverflow included source code which explain its usage and authentication with the server, for example:
Write/upload a file using Samba/JCIFS issue (SmbAuthException: Access is denied)
For an introduction see
http://durgemeister.wordpress.com/2014/04/26/mapping-a-network-with-jcifs-and-android/

What's a java equivalent for std::round(double)?

In cpp file I have std::round(double)
Please can I know the equivalent code in Java
Edit: I am already using java.lang.Math.round(double) and getting match in 99% cases. But in some places iam getting mismatch. For example:
std::round(4816.5058) = 4816 and Math.round(4816.5058) = 4817
std::round(4466.49996) = 4467 and Math.round(4466.49997) = 4466
java.lang.Math.round(double)

Categories

Resources