Re: Filter dataset by column value Wrapper Python

Peter Reutemann <[email protected]>
Newsgroups gmane.comp.ai.weka
Message-ID <CAHoQ12JAo5Y1NE-Vk+ORsE1BU4P=Vbv4_7+-RUUYUjU5F-d+Yg@mail.gmail.com>
> I would like to do this but using Wrapper.
>
> data_frame = pd.read_csv ('positions.csv')
> vehs= pd.unique(data_frame['id'])
>
> for i in range(0, len(vehs)):
>   df0 = data_frame[data_frame['id']==vehs[i]]
>   dat = np.array(df0[['latitude','longitude']])
>
> Is it possible to do it using Wrapper on the fly? I mean without saving them in parallel in CSV, convert them to arff and load them.

As long as your ID is a NOMINAL or STRING attribute, then yes (you can
use the NumericToNominal filter to turn a numeric ID attribute into a
nominal one).

For simplicity, the following example uses the class attribute of the
iris UCI dataset as ID for the subsets generated by the
SubsetByExpression filter (ATTx with x being 1-based index):

import weka.core.jvm as jvm
from weka.core.converters import load_any_file
from weka.filters import Filter

jvm.start()

data = load_any_file("/some/where/iris.arff")
vals = data.attribute(data.num_attributes - 1).values
for val in vals:
    print("\n\n", "-->", val, "\n")
    # generate subset
    f= Filter(classname="weka.filters.unsupervised.instance.SubsetByExpression",
           options=["-E", "ATT5 is '%s'" % val])
    f.inputformat(data)
    subdata = f.filter(data)
    # create subset of columns (you can also use col_range="1,2")
    subdata = subdata.subset(col_names=["sepallength", "sepalwidth"])
    print(subdata)  # here you would do something with the data

jvm.stop()

Cheers, Peter
-- 
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 858-5174 (office)
+64 (7) 577-5304 (home office)
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
_______________________________________________
Wekalist mailing list -- [email protected]
Send posts to [email protected]
To unsubscribe send an email to [email protected]
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.