I have two hundred and fifty images, and extracted the features from them and put them in an Excel file, how to use the weka program so that the first 200 images for training and the remaining fifty images for testing.

Do I put the data for two hundred images in a separate file and the data for fifty images in another file? Or do I put the data for two hundred and fifty images in the same file?. Please help me.

  • $\begingroup$ I'm voting to close this question as off-topic because this is better asked on DataScience.SE $\endgroup$
    – John Doucette
    Sep 17 '19 at 22:39

Data Preparation

Weka uses the arff file type.

A modified example arff file content from the previous link:

% 1. Title: Iris Plants Database
% 2. Creator: R.A. Fisher, Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)
@ATTRIBUTE class        {Iris-setosa,Iris-versicolor,Iris-virginica}

The above example can be broken down into sections:

    • Lines beginning with "%" are comments and are not read by the WEKA data readers
    • dataset name (use quotes around the name if there are spaces)
    • each attribute defines a feature of one of the following types:
      • NUMERIC: real number
      • NOMINAL: discrete value from a predefined list (see example @ATTRIBUTE class feature)
      • STRING: a string where quotes must be used if spaces are included
      • DATE: @ATTRIBUTE `name` date [`date-format`] where the default date-format is "yyyy-MM-dd'T'HH:mm:ss"
  4. @DATA
    • Delimiter specifying the start of the CSV data

Weka Explorer

After creating your arff file, you have a few options when using the Weka explorer:

  1. Load entire dataset into Weka explorer and use the built-in k-fold cross validation option which randomly partitions your dataset and automatically performs CV for your given a classifier
  2. Load entire dataset into Weka explorer and use the built-in train/test split option with a user-specified percentage to randomly partition your dataset.
  3. Manually partition your arff file into a train file and test file and use the supplied test-set option in the Weka explorer. To manually partition your arff file, simply copy your original arff file and and keep non-intersecting sets of CSV rows (i.e. delete instances from one file and retain those instances in the other).

If this is for educational purposes, it might be easiest to manually partition your dataset so that you know which images are in training and which are testing. If this is for research, of course k-fold CV is preferred.

If you are using the Weka Java library rather than the desktop application, there are plenty of online resources that explain the library architecture: Waikato Github io site


The answer to your question is to use Weka's "Explorer" mode, and then select "training/test split" with a 20% size for the test set.

  • $\begingroup$ Do you mean to divide the 250-cell data file to 20% for testing? Or separate 20% of the data in a separate file and use it for testing? $\endgroup$ Sep 18 '19 at 6:02
  • $\begingroup$ Weka's "Explorer" mode should have an option to select "training/test split" if you want to perform a classification task (at least, if did last time I used it). You can load a single file into the "Explorer" mode under the classification tab, and then tell Weka that you want the file to be split into training and test pieces. $\endgroup$ Sep 18 '19 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.