Can I use weka models with pandas dataframe?

143 views
Skip to first unread message

Mohanad Jibory

unread,
Feb 23, 2022, 11:50:48 AM2/23/22
to python-weka-wrapper
I want to call j48 classifier for my dataframe, will it work ?or I need to change to arff format in the code?

Best,

Peter Reutemann

unread,
Feb 23, 2022, 2:53:18 PM2/23/22
to python-weka-wrapper
> I want to call j48 classifier for my dataframe, will it work ?or I need to change to arff format in the code?

No, not directly as a Pandas dataframe is a Python data structure and
Weka uses Java data structures within the JVM that is running it.

However, for training you can convert numpy matrices into Weka's
Instances with already existing helper methods:
https://fracpete.github.io/python-weka-wrapper3/examples.html?highlight=pandas#create-dataset-from-matrices

When making predictions, you have to manually construct Instance
objects (ie invididual rows) according to the dataset structure.
Though the example below is for constructing an Instances object, it
still shows how to create Instance objects (ie rows) of data:
https://fracpete.github.io/python-weka-wrapper3/examples.html?highlight=pandas#create-dataset-manually

But rather than adding the newly created Instance object to an
Instances dataset, you only need to reference the dataset via the
"dataset" property of the Instance class (Weka needs to know the
dataset structure and column types):
https://fracpete.github.io/python-weka-wrapper3/weka.core.html?highlight=dataset#weka.core.dataset.Instance.dataset

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 858-5174 (office)
+64 (7) 577-5304 (home office)
https://www.cs.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
Reply all
Reply to author
Forward
0 new messages