Looking for XMeans

94 views
Skip to first unread message

Alexander Osherenko

unread,
May 4, 2017, 11:25:38 AM5/4/17
to python-we...@googlegroups.com
It must be quite stupid. I am looking for the class weka.clusterers.XMeans so that I can instantiate it in my Python-Script.

clst = Clusterer(classname="weka.clusterers.XMeans")

I looked for the class in the Python installation in Python_weka_wrapper3/weka/Lib directory in weka.jar, The class is not there. However, if I run the standalone Weka 3.8, the clusterer works in the GUI, but I don't find it in weka.jar. What do I miss?

Best, Alexander

Peter Reutemann

unread,
May 4, 2017, 4:59:38 PM5/4/17
to python-weka-wrapper
XMeans is now a package. You have to start up the JVM with package
support ("packages=True") to be able to use those algorithms:
http://pythonhosted.org/python-weka-wrapper3/api.html#java-virtual-machine

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 858-5174
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/

Alexander Osherenko

unread,
May 5, 2017, 12:12:38 AM5/5/17
to python-weka-wrapper, frac...@waikato.ac.nz
I did it as you said. Started jvm.start(packages=True). However, I still miss something since

clst = Clusterer(classname="weka.clusterers.XMeans")

or

clst = Clusterer(classname="weka.clusterers.xmeans.XMeans")

is not found. I would copy the clusterer in wekafiles directory as it is in your docu "jvm.start(packages="/my/packages/are/somwhere/else")". But I don't find the .class file and also the directory.

In GenericObjectEditor.props, the clusterer class is weka.clusterers.XMeans.

BTW, where can I find the full list of modules that were previously classes?

Peter Reutemann

unread,
May 5, 2017, 12:32:51 AM5/5/17
to python-weka-wrapper
> I did it as you said. Started jvm.start(packages=True). However, I still
> miss something since
>
> clst = Clusterer(classname="weka.clusterers.XMeans")

Correct classname.

> or
>
> clst = Clusterer(classname="weka.clusterers.xmeans.XMeans")

Incorrect classname.

> is not found. I would copy the clusterer in wekafiles directory as it is in
> your docu "jvm.start(packages="/my/packages/are/somwhere/else")". But I
> don't find the .class file and also the directory.

Don't copy your files around. If the packages are installed in the
default location (eg $HOME/wekafiles), then they will get found.

> In GenericObjectEditor.props, the clusterer class is weka.clusterers.XMeans.

Is the XMeans package actually installed? You can use pww3 to
query/install/remove packages as well:
http://pythonhosted.org/python-weka-wrapper3/api.html#packages

NB: pww3 uses Weka 3.9.1

> BTW, where can I find the full list of modules that were previously classes?

Not that I'm aware of. All packages are located here:
https://sourceforge.net/projects/weka/files/weka-packages/

Alexander Osherenko

unread,
May 5, 2017, 12:57:46 AM5/5/17
to python-weka-wrapper, frac...@waikato.ac.nz
I controlled in Gui of PackageManager -- XMeans is installed version 1.0.4.

Peter Reutemann

unread,
May 5, 2017, 1:05:56 AM5/5/17
to python-weka-wrapper
> I controlled in Gui of PackageManager -- XMeans is installed version 1.0.4.

Not sure what your setup is, but the following works for me:

import weka.core.jvm as jvm
import weka.core.packages as pkg
from weka.clusterers import Clusterer

jvm.start(packages=True)

# install package
if not pkg.is_installed("XMeans"):
pkg.install_package("XMeans")
print("Installed package, please restart!")
exit(0)

cls = Clusterer(classname="weka.clusterers.XMeans")
print(cls.to_commandline())

jvm.stop()

Which outputs (excluding the debug messages):

weka.clusterers.XMeans -I 1 -M 1000 -J 1000 -L 2 -H 4 -B 1.0 -C 0.5 -D
"weka.core.EuclideanDistance -R first-last" -S 10

Alexander Osherenko

unread,
May 5, 2017, 1:14:11 AM5/5/17
to python-weka-wrapper, frac...@waikato.ac.nz
When I run jvm.start(packages=True) from the IDLE

I get:
DEBUG:weka.core.jvm:Adding bundled jars
DEBUG:weka.core.jvm:Adding Weka packages
ERROR:weka.core.jvm:package_dir not found: D:\WinPython-64bit-3.4.3.7\settings\wekafiles\packages

Package dir is not found in WinPython, but is found in the standalone Weka 3.8.3, since Paxkage GUI finds it.?

Alexander Osherenko

unread,
May 5, 2017, 1:21:06 AM5/5/17
to python-weka-wrapper, frac...@waikato.ac.nz
If I run  pkg.is_installed("XMeans") from your script on IDLE I get the error message:

>> pkg.is_installed("XMeans")
Traceback (most recent call last):
  File "<pyshell#18>", line 1, in <module>
    pkg.is_installed("XMeans")
  File "D:\WinPython-64bit-3.4.3.7\python-3.4.3.amd64\lib\site-packages\python_weka_wrapper3-0.1.2-py3.4.egg\weka\core\packages.py", line 331, in is_installed
    pkgs = installed_packages()
  File "D:\WinPython-64bit-3.4.3.7\python-3.4.3.amd64\lib\site-packages\python_weka_wrapper3-0.1.2-py3.4.egg\weka\core\packages.py", line 269, in installed_packages
    establish_cache()
  File "D:\WinPython-64bit-3.4.3.7\python-3.4.3.amd64\lib\site-packages\python_weka_wrapper3-0.1.2-py3.4.egg\weka\core\packages.py", line 216, in establish_cache
    "weka/core/WekaPackageManager", "establishCacheIfNeeded", "([Ljava/io/PrintStream;)Ljava/lang/Exception;", [])
  File "D:\WinPython-64bit-3.4.3.7\python-3.4.3.amd64\lib\site-packages\javabridge\jutil.py", line 932, in static_call
    fn = make_static_call(class_name, method_name, sig)
  File "D:\WinPython-64bit-3.4.3.7\python-3.4.3.amd64\lib\site-packages\javabridge\jutil.py", line 903, in make_static_call
    klass = env.find_class(class_name)
AttributeError: 'NoneType' object has no attribute 'find_class'

Alexander Osherenko

unread,
May 5, 2017, 2:16:56 AM5/5/17
to python-weka-wrapper, frac...@waikato.ac.nz
There was probably a similar problem with installing packages in weka under WinPython:

Alexander Osherenko

unread,
May 5, 2017, 5:52:22 AM5/5/17
to python-weka-wrapper, frac...@waikato.ac.nz
Very tough, but I found it.

1. WinPython installation maintains own Python 3.4 and a corresponding PackageManager version that can't be confused with another PackageManager, for example, from the standalone Weka installation on "D:\Program Files\Weka-3-8". To avoid confusion, I first uninstalled PackageManager in the standalone application, opened the cmd console, moved to the D:\WinPython-64bit-3.4.3.7\python-3.4.3.amd64\Lib\site-packages\python_weka_wrapper3-0.1.2-py3.4.egg\weka\lib directory and called java -cp weka.jar weka.gui.PackageManager to open the WinPython-Weka-PackageManager and install the XMeans package in WinPython-python 3.4. While installation, PackageManager showed the path on the cmd console where the wekafiles directory was created containing, for instance, the package XMeans.jar. In my case, the wekafiles directory was created in the user directory C:\Users\osher.

NB: WinPython also maintains packages but these are its own packages -- for example, python-weka-wrapper3 is such a package which installation was performed from WinPython Control Panel by specifying precompiled wheel files. In this WinPython package, we have now to install own weka packages such as weka.clusteres.XMeans.

2. After creation, the wekafiles directory must be copied to the D:\WinPython-64bit-3.4.3.7\settings directory using Windows Explorer. Otherwise, jvm from Python-Weka-Wrapper can't find it and the command jvm.start(packages=True) fails.

PS. Maybe, the copying is obsolete and PackageManager can create the wekafiles directory directly in the WinPython\settings directory while installation, but it would need a corresponding path setting.

Peter Reutemann

unread,
May 6, 2017, 1:48:05 AM5/6/17
to python-weka-wrapper
In context of pww3, packages are always referring to Weka packages.

I'm not a Windows user and I only use the official Python installer
from python.org when testing on Windows, so I can't comment on other
installers.

Instead of "packages=True" and copying the files, simply put the path
name of the Weka home directory there ("wekafiles").

Cheers, Peter
> --
> You received this message because you are subscribed to the Google Groups
> "python-weka-wrapper" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to python-weka-wra...@googlegroups.com.
> To post to this group, send email to python-we...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python-weka-wrapper/12ed0d30-ed9f-47fb-8402-51281aab3d48%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Alexander Osherenko

unread,
May 6, 2017, 2:16:05 AM5/6/17
to python-we...@googlegroups.com
Thanks, Peter! I hope it was only necessary for XMeans and wouldn't happen often. Anyhow, is this classes-packages transform list long -- what other classes became packages or vice versa, some packages classes?


> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python-weka-wrapper/12ed0d30-ed9f-47fb-8402-51281aab3d48%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 858-5174
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/

--
You received this message because you are subscribed to a topic in the Google Groups "python-weka-wrapper" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python-weka-wrapper/bWrrZ5IrhPU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python-weka-wrapper+unsub...@googlegroups.com.
To post to this group, send email to python-weka-wrapper@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python-weka-wrapper/CAHoQ12L5RKsedVo6K97stOSvCYHf3SJwykpgmC8xN5iToZaWLA%40mail.gmail.com.

Peter Reutemann

unread,
May 6, 2017, 2:28:17 AM5/6/17
to python-weka-wrapper
> Anyhow, is this classes-packages transform list long -- what other
> classes became packages or vice versa, some packages classes?

The link (https://sourceforge.net/projects/weka/files/weka-packages/)
contains all the versions for every package. That creates a bit of
bloat, of course. Also, the package manager also links to contributed
packages (some of my packages on github can be installed like that).

The simplest would be for you to unzip a 3.6 and a 3.9 release and
compare the file lists. Personally, I don't know which classes have
been converted to packages, but a lot of the less-often-used stuff has
been moved out of the "core" distribution.
Reply all
Reply to author
Forward
0 new messages