How to know the number of attributes that remain after applying a filter?

15 views
Skip to first unread message

Dario Martinez

unread,
Apr 11, 2024, 1:14:55 AMApr 11
to python-weka-wrapper
Hello, I am applying the genetic search filter to the labor_data data set, and as seen in the following code, I store the filtered data in DataWorking, could someone help me by telling me how I can know the total number of attributes that were left in DataWorking, including the attribute to be classified:

Filtro = Filter(classname="weka.filters.supervised.attribute.AttributeSelection")
            aseval = ASEvaluation(classname="weka.attributeSelection.CfsSubsetEval",
                                  options=["-P", "1", "-E", "1"])
            ga_options = f"-S {num_seed_gen_search} -C {0.6} -M {0.033} -G {200} -Z {200} -R {20}".split()
            assearch = ASSearch(classname="weka.attributeSelection.GeneticSearch",
                               options=ga_options)
            Filtro.set_property("evaluator", aseval.jobject)
            Filtro.set_property("search", assearch.jobject)
            Filtro.inputformat(labor_data)
            DataWorking = Filtro.filter(labor_data)

Peter Reutemann

unread,
Apr 11, 2024, 1:21:19 AMApr 11
to python-we...@googlegroups.com

Dario Martinez

unread,
Apr 11, 2024, 7:59:35 AMApr 11
to python-we...@googlegroups.com
Ok Peter, thank you very much.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/python-weka-wrapper/CAHoQ12Krkhs7Vh0t5jNLh9zfUGa-QhLLcmueNJbQp46-xdBZiQ%40mail.gmail.com.

Dario Martinez

unread,
Apr 11, 2024, 9:06:19 AMApr 11
to python-we...@googlegroups.com
Hello again, I take this opportunity to ask you, if I wanted to know the degree of correlation between any pair of attributes, and also between any attribute and the attribute to be classified, how could I do it?

Peter Reutemann

unread,
Apr 11, 2024, 6:12:39 PMApr 11
to python-weka-wrapper
New question, new post with new subject please.

> Hello again, I take this opportunity to ask you, if I wanted to know the degree of correlation between any pair of attributes, and also between any attribute and the attribute to be classified, how could I do it?

You have two options:

1. use attribute selection

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

jvm.start()

data = load_any_file("/some/where/bolts.arff", class_index="last")

search = ASSearch(classname="weka.attributeSelection.Ranker", options=[])
evaluation = ASEvaluation(classname="weka.attributeSelection.CorrelationAttributeEval",
options=[])
attsel = AttributeSelection()
attsel.search(search)
attsel.evaluator(evaluation)
attsel.select_attributes(data)
print("# attributes: " + str(attsel.number_attributes_selected))
print("attributes (as numpy array): " + str(attsel.selected_attributes))
print("attributes (as list): " + str(list(attsel.selected_attributes)))
print("result string:\n" + attsel.results_string)

jvm.stop()


2. install pww3 from the github repo to take advantage of the the
weka.core.utils module that I just added and use the following code:

import weka.core.jvm as jvm
from weka.core.converters import load_any_file
from weka.core.utils import correlation

jvm.start()

data = load_any_file("/some/where/bolts.arff", class_index="last")
class_values = data.values(data.class_index)
for i in range(data.num_attributes - 1):
att_values = data.values(i)
print(data.attribute(i).name, correlation(att_values, class_values))

jvm.stop()

Dario Martinez

unread,
Apr 12, 2024, 1:49:00 AMApr 12
to python-we...@googlegroups.com
OK thanks

--
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.
Reply all
Reply to author
Forward
0 new messages