Trouble Running from Command Line

classic Classic list List threaded Threaded
22 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Trouble Running from Command Line

Oscar Bastidas
Hello,

I am trying to get started with Weka on the command line to develop my own Java programs and run a sample code named "Regression.java" from a github (https://github.com/shuchengc/weka-example/blob/master/Regression.java).

After downloading the Weka zip file and extracting it, I placed the aforemenioned code (shown in full at the end of this e-mail below) in the same directory as the "weka.jar" file.  I then compiled the code with "javac -cp weka.jar Regression.java" and it compiled fine.

But then I tried to run it by executing "java Regression" and I got an error that said:

"Unable to initialize main class Regression Caused by: java.lang.NoClassDefFoundError: weka/classifiers/Classifier"

I don't understand why I am getting this error as I haven't moved anything between compiling and running.  Would someone please help me troubleshoot this?

Here is the code I'm trying to run from github (thanks in advance):

import weka.classifiers.Evaluation;
import weka.classifiers.functions.LinearRegression;
import weka.classifiers.functions.SMOreg;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
public class Regression {
public static void main(String[] args) throws Exception{
DataSource source = new DataSource("house.arff");
Instances dataset = source.getDataSet();
dataset.setClassIndex(dataset.numAttributes()-1);
/**
* linear regression model
*/
LinearRegression lr = new LinearRegression();
lr.buildClassifier(dataset);
//System.out.println(lr);
Evaluation lreval = new Evaluation(dataset);
lreval.evaluateModel(lr, dataset);
System.out.println(lreval.toSummaryString());
/**
* svm regression model
*/
SMOreg smoreg = new SMOreg();
smoreg.buildClassifier(dataset);
Evaluation svmregeval = new Evaluation(dataset);
svmregeval.evaluateModel(smoreg, dataset);
System.out.println(svmregeval.toSummaryString());
}
}

Oscar B.

_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Peter Reutemann
> I am trying to get started with Weka on the command line to develop my own Java programs and run a sample code named "Regression.java" from a github (https://github.com/shuchengc/weka-example/blob/master/Regression.java).
>
> After downloading the Weka zip file and extracting it, I placed the aforemenioned code (shown in full at the end of this e-mail below) in the same directory as the "weka.jar" file.  I then compiled the code with "javac -cp weka.jar Regression.java" and it compiled fine.
>
> But then I tried to run it by executing "java Regression" and I got an error that said:

[...]

You're not including the weka.jar in your classpath when executing the
code. For example:
- Linux/Mac
  java -classpath weka.jar:. Regression
- Windows
  java -classpath weka.jar;. Regression

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 577-5304
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Oscar Bastidas
Hello Peter,

Thanks for your response.  I tried executing:

java -classpath weka.jar:. Regression

but I got the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: no/uib/cipr/matrix/Matrix
        at Regression.main(Regression.java:28)

I noticed there are other jar files called weka-src.jar and remoteExperimentServer.jar, but I didn't need to include them in order to compile (since not including them didn't generate a compile error).

Would you please tell me, what could be triggering this error?  Thanks.

Oscar



On Sun, Jan 17, 2021, 4:38 PM Peter Reutemann <[hidden email]> wrote:
> I am trying to get started with Weka on the command line to develop my own Java programs and run a sample code named "Regression.java" from a github (https://github.com/shuchengc/weka-example/blob/master/Regression.java).
>
> After downloading the Weka zip file and extracting it, I placed the aforemenioned code (shown in full at the end of this e-mail below) in the same directory as the "weka.jar" file.  I then compiled the code with "javac -cp weka.jar Regression.java" and it compiled fine.
>
> But then I tried to run it by executing "java Regression" and I got an error that said:

[...]

You're not including the weka.jar in your classpath when executing the
code. For example:
- Linux/Mac
  java -classpath weka.jar:. Regression
- Windows
  java -classpath weka.jar;. Regression

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 577-5304
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Peter Reutemann
> Thanks for your response.  I tried executing:
>
> java -classpath weka.jar:. Regression
>
> but I got the following error:
>
> Exception in thread "main" java.lang.NoClassDefFoundError: no/uib/cipr/matrix/Matrix
>         at Regression.main(Regression.java:28)
>
> I noticed there are other jar files called weka-src.jar and remoteExperimentServer.jar, but I didn't need to include them in order to compile (since not including them didn't generate a compile error).
>
> Would you please tell me, what could be triggering this error?  Thanks.

The package management subsystem hasn't initialized yet.
LinearRegression nowadays uses some other libraries for matrix
calculations. Though these libraries are bundled with the weka.jar,
they still need to be initialized.

Add the following line as the first in your main method:
weka.gui.GenericObjectEditor.determineClasses();

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 577-5304
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Oscar Bastidas
I'm running on a headless/terminal environment and I'm getting the following error pertaining to the GUI part of the new command you gave me:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by weka.core.WekaPackageClassLoaderManager (file:/storage/emulated/0/Download/weka-3-8-5/weka.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of weka.core.WekaPackageClassLoaderManager
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Exception in thread "main" java.lang.UnsatisfiedLinkError: no awt in java.library.path

Can Weka not be used on a headless server environment?  Thanks.

Oscar

On Sun, Jan 17, 2021, 8:20 PM Peter Reutemann <[hidden email]> wrote:
> Thanks for your response.  I tried executing:
>
> java -classpath weka.jar:. Regression
>
> but I got the following error:
>
> Exception in thread "main" java.lang.NoClassDefFoundError: no/uib/cipr/matrix/Matrix
>         at Regression.main(Regression.java:28)
>
> I noticed there are other jar files called weka-src.jar and remoteExperimentServer.jar, but I didn't need to include them in order to compile (since not including them didn't generate a compile error).
>
> Would you please tell me, what could be triggering this error?  Thanks.

The package management subsystem hasn't initialized yet.
LinearRegression nowadays uses some other libraries for matrix
calculations. Though these libraries are bundled with the weka.jar,
they still need to be initialized.

Add the following line as the first in your main method:
weka.gui.GenericObjectEditor.determineClasses();

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 577-5304
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Peter Reutemann
> I'm running on a headless/terminal environment

That would have been good to know beforehand. ;-)

> and I'm getting the following error pertaining to the GUI part of the new command you gave me:
>
> WARNING: An illegal reflective access operation has occurred
> WARNING: Illegal reflective access by weka.core.WekaPackageClassLoaderManager (file:/storage/emulated/0/Download/weka-3-8-5/weka.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
> WARNING: Please consider reporting this to the maintainers of weka.core.WekaPackageClassLoaderManager
> WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
> WARNING: All illegal access operations will be denied in a future release
> Exception in thread "main" java.lang.UnsatisfiedLinkError: no awt in java.library.path
>
> Can Weka not be used on a headless server environment?  Thanks.

Sure, you just need a different API call to initialize things (without
initializing GUI related things).

Replace the previous line of code with this one:
weka.core.WekaPackageManager.loadPackages(false);

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 577-5304
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Oscar Bastidas
I tried it and got the same error:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by weka.core.WekaPackageClassLoaderManager (file:/storage/emulated/0/Download/weka-3-8-5/weka.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of weka.core.WekaPackageClassLoaderManager
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Exception in thread "main" java.lang.UnsatisfiedLinkError: no awt in java.library.path

It's still looking for awt!

Oscar B.

On Sun, Jan 17, 2021, 8:40 PM Peter Reutemann <[hidden email]> wrote:
> I'm running on a headless/terminal environment

That would have been good to know beforehand. ;-)

> and I'm getting the following error pertaining to the GUI part of the new command you gave me:
>
> WARNING: An illegal reflective access operation has occurred
> WARNING: Illegal reflective access by weka.core.WekaPackageClassLoaderManager (file:/storage/emulated/0/Download/weka-3-8-5/weka.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
> WARNING: Please consider reporting this to the maintainers of weka.core.WekaPackageClassLoaderManager
> WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
> WARNING: All illegal access operations will be denied in a future release
> Exception in thread "main" java.lang.UnsatisfiedLinkError: no awt in java.library.path
>
> Can Weka not be used on a headless server environment?  Thanks.

Sure, you just need a different API call to initialize things (without
initializing GUI related things).

Replace the previous line of code with this one:
weka.core.WekaPackageManager.loadPackages(false);

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 577-5304
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Peter Reutemann
> I tried it and got the same error:
>
> WARNING: An illegal reflective access operation has occurred
> WARNING: Illegal reflective access by weka.core.WekaPackageClassLoaderManager (file:/storage/emulated/0/Download/weka-3-8-5/weka.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
> WARNING: Please consider reporting this to the maintainers of weka.core.WekaPackageClassLoaderManager
> WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
> WARNING: All illegal access operations will be denied in a future release
> Exception in thread "main" java.lang.UnsatisfiedLinkError: no awt in java.library.path
>
> It's still looking for awt!

Hmm...  I ran my class on my Linux laptop in headless mode (using
"java -Djava.awt.headless=true ...") and it didn't complain.

What's your Java version that you are using? I'm using:
openjdk version "11.0.7" 2020-04-14

NB: I never use the JDKs that come with Linux distros, instead I
download mine from here:
https://adoptopenjdk.net/releases.html

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 577-5304
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Oscar Bastidas
I'm using Java 9 and I'm specifically running it through Termux, a Linux emulator app for Android tablets (it's strictly command line).  I've been able to develop and run pure standalone Java prigrams (all command line), so that's why I thought the Weka library would work.  Thanks for helping out.

Oscar

On Sun, Jan 17, 2021, 9:05 PM Peter Reutemann <[hidden email]> wrote:
> I tried it and got the same error:
>
> WARNING: An illegal reflective access operation has occurred
> WARNING: Illegal reflective access by weka.core.WekaPackageClassLoaderManager (file:/storage/emulated/0/Download/weka-3-8-5/weka.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
> WARNING: Please consider reporting this to the maintainers of weka.core.WekaPackageClassLoaderManager
> WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
> WARNING: All illegal access operations will be denied in a future release
> Exception in thread "main" java.lang.UnsatisfiedLinkError: no awt in java.library.path
>
> It's still looking for awt!

Hmm...  I ran my class on my Linux laptop in headless mode (using
"java -Djava.awt.headless=true ...") and it didn't complain.

What's your Java version that you are using? I'm using:
openjdk version "11.0.7" 2020-04-14

NB: I never use the JDKs that come with Linux distros, instead I
download mine from here:
https://adoptopenjdk.net/releases.html

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 577-5304
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Peter Reutemann
> I'm using Java 9 and I'm specifically running it through Termux, a Linux emulator app for Android tablets (it's strictly command line).  I've been able to develop and run pure standalone Java prigrams (all command line), so that's why I thought the Weka library would work.  Thanks for helping out.

I use Weka algorithms through my ADAMS framework in headless
environments. But this happens on Windows/Linux servers as
services/daemons and not on Android.

As an alternative, you could try the following:
- remove the "WekaPackageManager" line again from your code
- extract the bundled jar files (mtj.jar, core.jar, arpack_combined.jar)
- add the jar files to your classpath, eg (adjust paths if necessary):
  java -classpath weka.jar:core.jar:arpack_combined.jar:mtj.jar:. ...

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 577-5304
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Michael Hall
In reply to this post by Peter Reutemann


On Jan 17, 2021, at 9:05 PM, Peter Reutemann <[hidden email]> wrote:

java -Djava.awt.headless=true

I’m not sure exactly what instantiates awt to make it non-headless. But given…

public class Test2 {

public static void main(String[] args) {
weka.core.WekaPackageManager.loadPackages(false);
}
}

You get…

java -Djava.awt.headless=true -verbose:class -cp .:/Applications/weka-3-9-5/weka.jar Test2 | grep awt 
[0.083s][info][class,load] java.awt.GraphicsEnvironment source: jrt:/java.desktop
[0.083s][info][class,load] java.awt.GraphicsEnvironment$$Lambda$2/0x0000000800b67c40 source: java.awt.GraphicsEnvironment
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by weka.core.WekaPackageClassLoaderManager (file:/Applications/weka-3-9-5/weka.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of weka.core.WekaPackageClassLoaderManager
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[3.010s][info][class,load] java.awt.event.WindowListener source: jrt:/java.desktop

It clearly loads awt classes.

java -version
java version "14.0.2" 2020-07-14
Java(TM) SE Runtime Environment (build 14.0.2+12-46)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Oscar Bastidas
In reply to this post by Peter Reutemann
Sounds good, I'll try that.  My question now is from where do I get the bundled jars file from which I should extract mtj.jar, core.jar and arpack_combined.jar?  Thanks.

Oscar B.

On Sun, Jan 17, 2021, 9:43 PM Peter Reutemann <[hidden email]> wrote:
> I'm using Java 9 and I'm specifically running it through Termux, a Linux emulator app for Android tablets (it's strictly command line).  I've been able to develop and run pure standalone Java prigrams (all command line), so that's why I thought the Weka library would work.  Thanks for helping out.

I use Weka algorithms through my ADAMS framework in headless
environments. But this happens on Windows/Linux servers as
services/daemons and not on Android.

As an alternative, you could try the following:
- remove the "WekaPackageManager" line again from your code
- extract the bundled jar files (mtj.jar, core.jar, arpack_combined.jar)
- add the jar files to your classpath, eg (adjust paths if necessary):
  java -classpath weka.jar:core.jar:arpack_combined.jar:mtj.jar:. ...

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 577-5304
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Oscar Bastidas
In reply to this post by Michael Hall
Thanks also for verifying this.

Oscar B.

On Sun, Jan 17, 2021, 9:50 PM Michael Hall <[hidden email]> wrote:


On Jan 17, 2021, at 9:05 PM, Peter Reutemann <[hidden email]> wrote:

java -Djava.awt.headless=true

I’m not sure exactly what instantiates awt to make it non-headless. But given…

public class Test2 {

public static void main(String[] args) {
weka.core.WekaPackageManager.loadPackages(false);
}
}

You get…

java -Djava.awt.headless=true -verbose:class -cp .:/Applications/weka-3-9-5/weka.jar Test2 | grep awt 
[0.083s][info][class,load] java.awt.GraphicsEnvironment source: jrt:/java.desktop
[0.083s][info][class,load] java.awt.GraphicsEnvironment$$Lambda$2/0x0000000800b67c40 source: java.awt.GraphicsEnvironment
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by weka.core.WekaPackageClassLoaderManager (file:/Applications/weka-3-9-5/weka.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of weka.core.WekaPackageClassLoaderManager
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[3.010s][info][class,load] java.awt.event.WindowListener source: jrt:/java.desktop

It clearly loads awt classes.

java -version
java version "14.0.2" 2020-07-14
Java(TM) SE Runtime Environment (build 14.0.2+12-46)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Peter Reutemann-3
In reply to this post by Oscar Bastidas
They are bundled in the weka.jar.

The package manager loads them normally from there. But if you don't use the package manager, you have to do it yourself.

I usually use Weka only through Maven, so I don't deal with it that way at all.

Cheers, Peter

On January 18, 2021 5:48:01 PM GMT+13:00, Oscar Bastidas <[hidden email]> wrote:

>Sounds good, I'll try that.  My question now is from where do I get the
>bundled jars file from which I should extract mtj.jar, core.jar and
>arpack_combined.jar?  Thanks.
>
>Oscar B.
>
>On Sun, Jan 17, 2021, 9:43 PM Peter Reutemann <[hidden email]>
>wrote:
>
>> > I'm using Java 9 and I'm specifically running it through Termux, a
>Linux
>> emulator app for Android tablets (it's strictly command line).  I've
>been
>> able to develop and run pure standalone Java prigrams (all command
>line),
>> so that's why I thought the Weka library would work.  Thanks for
>helping
>> out.
>>
>> I use Weka algorithms through my ADAMS framework in headless
>> environments. But this happens on Windows/Linux servers as
>> services/daemons and not on Android.
>>
>> As an alternative, you could try the following:
>> - remove the "WekaPackageManager" line again from your code
>> - extract the bundled jar files (mtj.jar, core.jar,
>arpack_combined.jar)
>> - add the jar files to your classpath, eg (adjust paths if
>necessary):
>>   java -classpath weka.jar:core.jar:arpack_combined.jar:mtj.jar:. ...
>>
>> Cheers, Peter
>> --
>> Peter Reutemann
>> Dept. of Computer Science
>> University of Waikato, NZ
>> +64 (7) 577-5304
>> http://www.cms.waikato.ac.nz/~fracpete/
>> http://www.data-mining.co.nz/
>> _______________________________________________
>> Wekalist mailing list -- [hidden email]
>> Send posts to [hidden email]
>> To unsubscribe send an email to [hidden email]
>> To subscribe, unsubscribe, etc., visit
>>
>https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
>> List etiquette:
>> http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
>>

--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 577-5304
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Oscar Bastidas
Hi Peter,

If I use Maven or do it manually by unbundling the weka.jar file, do I need to include a special line of code (something comparable to "weka.core.WekaPackageManager.loadPackages(false);") in the main method to get it to work?  Thanks.

Oscar

Oscar Bastidas, Ph.D.
Postdoctoral Research Associate
University of Minnesota


On Sun, Jan 17, 2021, 11:42 PM Peter Reutemann <[hidden email]> wrote:
They are bundled in the weka.jar.

The package manager loads them normally from there. But if you don't use the package manager, you have to do it yourself.

I usually use Weka only through Maven, so I don't deal with it that way at all.

Cheers, Peter

On January 18, 2021 5:48:01 PM GMT+13:00, Oscar Bastidas <[hidden email]> wrote:
>Sounds good, I'll try that.  My question now is from where do I get the
>bundled jars file from which I should extract mtj.jar, core.jar and
>arpack_combined.jar?  Thanks.
>
>Oscar B.
>
>On Sun, Jan 17, 2021, 9:43 PM Peter Reutemann <[hidden email]>
>wrote:
>
>> > I'm using Java 9 and I'm specifically running it through Termux, a
>Linux
>> emulator app for Android tablets (it's strictly command line).  I've
>been
>> able to develop and run pure standalone Java prigrams (all command
>line),
>> so that's why I thought the Weka library would work.  Thanks for
>helping
>> out.
>>
>> I use Weka algorithms through my ADAMS framework in headless
>> environments. But this happens on Windows/Linux servers as
>> services/daemons and not on Android.
>>
>> As an alternative, you could try the following:
>> - remove the "WekaPackageManager" line again from your code
>> - extract the bundled jar files (mtj.jar, core.jar,
>arpack_combined.jar)
>> - add the jar files to your classpath, eg (adjust paths if
>necessary):
>>   java -classpath weka.jar:core.jar:arpack_combined.jar:mtj.jar:. ...
>>
>> Cheers, Peter
>> --
>> Peter Reutemann
>> Dept. of Computer Science
>> University of Waikato, NZ
>> +64 (7) 577-5304
>> http://www.cms.waikato.ac.nz/~fracpete/
>> http://www.data-mining.co.nz/
>> _______________________________________________
>> Wekalist mailing list -- [hidden email]
>> Send posts to [hidden email]
>> To unsubscribe send an email to [hidden email]
>> To subscribe, unsubscribe, etc., visit
>>
>https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
>> List etiquette:
>> http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
>>

--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 577-5304
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html


_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Michael Hall
In reply to this post by Peter Reutemann-3


On Jan 17, 2021, at 11:41 PM, Peter Reutemann <[hidden email]> wrote:

They are bundled in the weka.jar.

The package manager loads them normally from there. But if you don't use the package manager, you have to do it yourself.

I usually use Weka only through Maven, so I don't deal with it that way at all.

Cheers, Peter

On January 18, 2021 5:48:01 PM GMT+13:00, Oscar Bastidas <[hidden email]> wrote:
Sounds good, I'll try that.  My question now is from where do I get the
bundled jars file from which I should extract mtj.jar, core.jar and
arpack_combined.jar?  Thanks.


This also appears to be the case…

jar -tvf /Applications/weka-3-9-5/weka.jar | grep jar
     0 Mon Dec 21 14:50:58 CST 2020 org/apache/commons/compress/archivers/jar/
1204349 Mon Dec 21 14:50:58 CST 2020 arpack_combined.jar
164422 Mon Dec 21 14:50:58 CST 2020 core.jar
271988 Mon Dec 21 14:50:58 CST 2020 mtj.jar

So something like…

jar -xvf /Applications/weka-3-9-5/weka.jar mtj.jar 
 inflated: mtj.jar

Should work.



_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Michael Hall


On Jan 18, 2021, at 5:09 AM, Michael Hall <[hidden email]> wrote:



On Jan 17, 2021, at 11:41 PM, Peter Reutemann <[hidden email]> wrote:

They are bundled in the weka.jar.

The package manager loads them normally from there. But if you don't use the package manager, you have to do it yourself.

I usually use Weka only through Maven, so I don't deal with it that way at all.

Cheers, Peter

On January 18, 2021 5:48:01 PM GMT+13:00, Oscar Bastidas <[hidden email]> wrote:
Sounds good, I'll try that.  My question now is from where do I get the
bundled jars file from which I should extract mtj.jar, core.jar and
arpack_combined.jar?  Thanks.


This also appears to be the case…

jar -tvf /Applications/weka-3-9-5/weka.jar | grep jar
     0 Mon Dec 21 14:50:58 CST 2020 org/apache/commons/compress/archivers/jar/
1204349 Mon Dec 21 14:50:58 CST 2020 arpack_combined.jar
164422 Mon Dec 21 14:50:58 CST 2020 core.jar
271988 Mon Dec 21 14:50:58 CST 2020 mtj.jar

So something like…

jar -xvf /Applications/weka-3-9-5/weka.jar mtj.jar 
 inflated: mtj.jar

Should work.

mtj.jar looks to be sufficient but you get some warning messages.

java -cp .:mtj.jar:/Applications/weka-3-9-5/weka.jar Regression
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by weka.core.WekaPackageClassLoaderManager (file:/Applications/weka-3-9-5/weka.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of weka.core.WekaPackageClassLoaderManager
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Jan 18, 2021 5:19:24 AM com.github.fommil.netlib.BLAS <clinit>
WARNING: Failed to load implementation from: com.github.fommil.netlib.NativeSystemBLAS
Jan 18, 2021 5:19:24 AM com.github.fommil.netlib.BLAS <clinit>
WARNING: Failed to load implementation from: com.github.fommil.netlib.NativeRefBLAS
Jan 18, 2021 5:19:24 AM com.github.fommil.netlib.LAPACK <clinit>
WARNING: Failed to load implementation from: com.github.fommil.netlib.NativeSystemLAPACK
Jan 18, 2021 5:19:24 AM com.github.fommil.netlib.LAPACK <clinit>
WARNING: Failed to load implementation from: com.github.fommil.netlib.NativeRefLAPACK

Correlation coefficient                  0.9952
Mean absolute error                   6675.9638
Root mean squared error               8972.2722
Relative absolute error                  9.3025 %
Root relative squared error              9.8048 %
Total Number of Instances                7     
Ignored Class Unknown Instances                  1     


Correlation coefficient                  0.9965
Mean absolute error                   3710.5667
Root mean squared error               8158.4038
Relative absolute error                  5.1704 %
Root relative squared error              8.9154 %
Total Number of Instances                7     
Ignored Class Unknown Instances                  1    

You get more warning messages if you include all 3 jars? 

Are you out of the Twin Cities? 


_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Peter Reutemann
In reply to this post by Oscar Bastidas
> If I use Maven or do it manually by unbundling the weka.jar file, do I need to include a special line of code (something comparable to "weka.core.WekaPackageManager.loadPackages(false);") in the main method to get it to work?  Thanks.

When I tested it with the unbundled jars, I didn't need the package
manager call.

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 577-5304
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Michael Hall
In reply to this post by Oscar Bastidas


On Jan 18, 2021, at 12:14 AM, Oscar Bastidas <[hidden email]> wrote:

Hi Peter,

If I use Maven or do it manually by unbundling the weka.jar file, do I need to include a special line of code (something comparable to "weka.core.WekaPackageManager.loadPackages(false);") in the main method to get it to work?  Thanks.

Oscar

Oscar Bastidas, Ph.D.
Postdoctoral Research Associate
University of Minnesota

I believe my prior post demonstrated this. However, you obtain the jars, and using the weka.jar included ones might best ensure weka compatibility, you can run the code as is. 
I haven’t done much of anything with Maven it may have advantages as well. 
I used exactly your code and a googled house.arff. 
You do get additional warnings.



_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Running from Command Line

Oscar Bastidas
In reply to this post by Peter Reutemann
Hello,

So I was able to get Weka installed, somewhat, using Maven.

The question I now have is: why do I get the following warning?

WARNING: Failed to load implementation from: com.github.fommil.netlib.NativeSystemARPACK
Jan 29, 2021 4:49:05 AM com.github.fommil.netlib.ARPACK <clinit>

along with other similarly worded errors pertaining to this "com.github.fommil.netlib.Native..." dependency.  Please correct me if I'm wrong, but does Weka use any native dependencies?  I thought Weka was written only in Java and so I didn't have to worry about native libraries.  By the way, at the end of the above warnings, the program prints out the below output, which indicated Java itself didn't exactly crash (this confuses me as to why Java returned the above warnings in the first place but didn't exactly crash - why didn't it crash?).

Correlation coefficient                  0.9945
Mean absolute error                   4053.821
Root mean squared error               4578.4125
Relative absolute error                 13.1339 %
Root relative squared error             10.51   %
Total Number of Instances                7

Correlation coefficient                  0.9937
Mean absolute error                   2445.4066
Root mean squared error               5015.3412
Relative absolute error                  7.9228 %
Root relative squared error             11.513  %
Total Number of Instances                7

The code I was trying to run is:

package com.obastida.weka;

import weka.core.Instances;
import weka.experiment.InstanceQuery;
import weka.classifiers.Evaluation;
import weka.classifiers.*;
import weka.classifiers.functions.LinearRegression;
import weka.classifiers.functions.SMOreg;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
public class App
{
    public static void main( String[] args ) throws Exception
    {
        DataSource source = new DataSource("house.arff");
                Instances dataset = source.getDataSet();
                dataset.setClassIndex(dataset.numAttributes()-1);
                /**
                 * linear regression model
                 */
                LinearRegression lr = new LinearRegression();
                lr.buildClassifier(dataset);
                //System.out.println(lr);
                Evaluation lreval = new Evaluation(dataset);
                lreval.evaluateModel(lr, dataset);
                System.out.println(lreval.toSummaryString());
                /**
                 * svm regression model
                 */
                SMOreg smoreg = new SMOreg();
                smoreg.buildClassifier(dataset);
                Evaluation svmregeval = new Evaluation(dataset);
                svmregeval.evaluateModel(smoreg, dataset);
                System.out.println(svmregeval.toSummaryString());
    }
}

Below is the Maven dependency for Weka 3.8.5 in my pom file:

<dependency>
<groupId>nz.ac.waikato.cms.weka</groupId>
<artifactId>weka-stable</artifactId>
<version>3.8.5</version>                                                                                  </dependency>

Would you please tell me what is causing the above behavior?  Are the results meaningless given the presence of the warnings?  Thanks.

Oscar

Oscar Bastidas, Ph.D.
Postdoctoral Research Associate
University of Minnesota


On Mon, Jan 18, 2021, 4:21 PM Peter Reutemann <[hidden email]> wrote:
> If I use Maven or do it manually by unbundling the weka.jar file, do I need to include a special line of code (something comparable to "weka.core.WekaPackageManager.loadPackages(false);") in the main method to get it to work?  Thanks.

When I tested it with the unbundled jars, I didn't need the package
manager call.

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 577-5304
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
12