How to Install weka.attributeSelection.GeneticSearch

20 views
Skip to first unread message

Juan José Expósito González

unread,
Feb 12, 2024, 10:33:49 AMFeb 12
to python-weka-wrapper
Hi,

I am trying to use GeneticSearch for attribute seleciton with the python-wekawrapper3 in python. I have tried to pass the option auto_install=True to the jvm.start() command, but it keeps failing. Shall I copy the .jar file and indicate (somehow) where to find this package?

Thanks and kindest regards,

JJ

Peter Reutemann

unread,
Feb 12, 2024, 2:43:26 PMFeb 12
to python-we...@googlegroups.com
> I am trying to use GeneticSearch for attribute seleciton with the python-wekawrapper3 in python. I have tried to pass the option auto_install=True to the jvm.start() command, but it keeps failing. Shall I copy the .jar file and indicate (somehow) where to find this package?

Since you neither posted code nor error messages, I can't comment on
what's going wrong.
The following code executes just fine the second time it is execute
(during the first run, the missing package gets installed):

import weka.core.jvm as jvm
from weka.core.converters import load_any_file
from weka.attribute_selection import ASSearch
from weka.attribute_selection import ASEvaluation
from weka.attribute_selection import AttributeSelection

jvm.start(packages=True, auto_install=True)
data = load_any_file("/home/fracpete/development/datasets/uci/anneal.arff",
class_index="last")
search = ASSearch(classname="weka.attributeSelection.GeneticSearch", options=[])
evaluation = ASEvaluation(classname="weka.attributeSelection.CfsSubsetEval",
options=["-P", "1", "-E", "1"])
attsel = AttributeSelection()
attsel.search(search)
attsel.evaluator(evaluation)
attsel.select_attributes(data)
print(attsel.results_string)
jvm.stop()

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, Hamilton, NZ
Mobile +64 22 190 2375
https://www.cs.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/

Juan José Expósito González

unread,
Feb 12, 2024, 3:17:28 PMFeb 12
to python-weka-wrapper
Hi Peter, again, thanks for your quick help. I had the following error: 

Exception in thread "Thread-0" java.lang.Exception: Can't find a permissible class called: weka.attributeSelection.GeneticSearch
        weka.core.ResourceUtils.forName(ResourceUtils.java:84)
        weka.core.Utils.forName(Utils.java:1112)
        weka.attributeSelection.ASEvaluation.forName(ASEvaluation.java:168)
        weka.filters.supervised.attribute.AttributeSelection.setOptions(AttributeSelection.java:285)

        at weka.core.ResourceUtils.forName(ResourceUtils.java:84)
        at weka.core.Utils.forName(Utils.java:1112)
        at weka.attributeSelection.ASEvaluation.forName(ASEvaluation.java:168)
        at weka.filters.supervised.attribute.AttributeSelection.setOptions(AttributeSelection.java:285)
Can't find a permissible class called: weka.attributeSelection.GeneticSearch

I thought it was because he GeneticSearch wasn't installed somehow (since it is a package you need to install through the package manager in Weka)... I have found that I was trying to use:
attribute_selection = Filter(
        classname="weka.filters.supervised.attribute.AttributeSelection",
        options=[
            "-E",
            "weka.attributeSelection.GeneticSearch",
            "-S",
            f"1 -C {crossover_probability} -M {mutation_probability} -V {max_generations} -P {population_size} -R {report_frequency} -s {genetic_seed}",
        ],
And therefore, I was doing it all wrong... I have already fixed it.

Kindes Regards,

JJ
Reply all
Reply to author
Forward
0 new messages