Learning Weka on the Command Line
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Weka (Waikato Environment for Knowledge Analysis) is a Java-based machine learning toolkit with a GUI and a powerful command-line interface. While the GUI is useful for exploration, the command line is essential for automation, scripting, reproducible experiments, and processing large datasets on servers without a display. Every Weka algorithm can be invoked from the command line with full parameter control.
Prerequisites
Loading and Inspecting Data
Weka uses ARFF (Attribute-Relation File Format) as its native format, but can read CSV files too:
ARFF File Format
Running Classifiers
Decision Tree (J48)
Random Forest
Naive Bayes
SVM (SMO)
Train/Test Split
Saving and Loading Models
Data Preprocessing (Filters)
Clustering
Feature Selection
Scripting and Automation
Common Pitfalls
- Memory for large datasets: Weka loads the entire dataset into memory. For large files, increase the JVM heap:
java -Xmx4g -cp $WEKAJAR .... Without this, you getOutOfMemoryError. - Class attribute position: Weka assumes the last attribute is the class by default. If your class column is not last, specify it with
-c(e.g.,-c 1for the first column). - ARFF format errors: Missing quotes around nominal values with spaces, incorrect
@attributedeclarations, or mismatched data types cause cryptic parsing errors. Validate your ARFF file before running experiments. - Classpath issues: Weka packages (installed via the Package Manager) are not automatically on the classpath. Add them:
java -cp $WEKAJAR:~/wekafiles/packages/*/weka.jar ...or load them programmatically. - Reproducibility: Set the random seed with
-sfor randomized algorithms (e.g.,-s 42) to ensure reproducible results across runs.
Summary
- Run any Weka classifier from the command line:
java -cp weka.jar weka.classifiers.trees.J48 -t data.arff -x 10 - Use
-tfor training file,-Tfor test file,-xfor cross-validation folds,-d/-lto save/load models - Preprocess data with filters:
weka.filters.unsupervised.attribute.Normalize,Remove,Discretize - Use
FilteredClassifierto chain preprocessing and classification in one command - Increase memory with
-Xmx4gfor large datasets - Script multiple experiments in bash for systematic comparisons
Related reading
System design interview problems on this topic
- Design an E-commerce Recommendation System: solution and walkthrough
- Design an LLM Inference Service: solution and walkthrough
- Design a GPU Cluster Scheduler for ML Training: solution and walkthrough
- Design ChatGPT: solution and walkthrough
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseThere is a whole course on this
Basis Lab has written “Training a Model From Scratch”, a course that teaches this from the ground up rather than answering the single question. It is a separate product from the same team and the course is free to read.
Read the courseML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.