fracpete / sklearn-weka-plugin

Makes Weka algorithms available in scikit-learn, by using python-weka-wrapper3 under the hood.
https://fracpete.github.io/sklearn-weka-plugin/
GNU General Public License v3.0
16 stars 1 forks source link

label ranking #11

Closed erelsgl closed 2 weeks ago

erelsgl commented 3 weeks ago

Hi. I would like to use algorithms for label ranking in Python. The algorithms are available in Weka here: https://en.cs.uni-paderborn.de/is/research/research-projects/software/weka-lr-a-label-ranking-extension-for-weka Is it possible to use them through sklearn-weka-plugin? I am particularly interested in the decision tree based algorithm (also called LRT - "label ranking tree"). Thanks!

fracpete commented 3 weeks ago

Unfortunately, no. The above link points to a really old and heavily modified version of Weka 3.7.2. sklearn-weka-plugin uses Weka 3.9.6.

But, you can still use the modified Weka version if you are willing to be a bit more low-level. This is possible using the jpype library:

# tested with
# - Java 1.8.0_292
# - Python 3.8.10
# - jpype 1.5.0
import jpype
import jpype.imports
from jpype import JClass

# start jvm
jvm_args = ["-Xmx1g"]
cp = ["./WEKA-LR.jar", "./lib/*"]
jpype.startJVM(*jvm_args, classpath=cp, convertStrings=True)

from weka.core.converters.ConverterUtils import DataSource
data = DataSource.read("./datasets/bodyfat_dense.xarff")
data.setClassIndex(data.numAttributes() - 1)

lrt = JClass("weka.classifiers.labelranking.LRT")()
lrt.setOptions([])  # set appropriate options
lrt.buildClassifier(data)
print(lrt)

# stop jvm
jpype.shutdownJVM()
erelsgl commented 3 weeks ago

I do not really need the old version - I just need any algorithm for label ranking. Is there any label ranking algorithm that can be used with sklearn-weka-plugin directly?

fracpete commented 3 weeks ago

I've never used label ranking and am not aware of such an algorithm in Weka. Have you checked the available Weka packages whether there is one in there?