An introduction to Weka for Machine Learning
This article is for the benefit of those starting out in machine learning who are looking for a tool that does not require coding capabilities. (Coders also welcome!)
Machine learning is essentially a way for computers to improve their performance on a specific task by using algorithms to analyse data and find patterns that allow them to make better predictions or decisions in the future.
There are many different tools that can be used to conduct machine learning. Popular picks include Tensor Flow and PyTorch. Scikit-learn, a machine learning library which is accessible through Python is like a Swiss Army knife for data scientists. It has all sorts of tools that can be used to analyse and manipulate data, making it a versatile and powerful option.
For the purpose of this article, we are considering Weka, a tool that supports a range of existing machine learning tools within it’s own package. You can be up and running with this in around 20 minutes.
Strictly speaking, Weka is a tool associated with Java, but you don’t need to be able to code in Java to operate it. Unlike library packages, Weka is a Graphic User Interface (GUI) that enables you to upload csv files and process the data using ‘point and click’ tools.
Weka’s distinctive logo:
There are some limitations to Weka, however given how fast and powerful it can be, don’t let these get in your way.
Limitations:
> Size: I use around 150k rows of data at a time. This can sometimes cause problems for the stack heap and it’s better to find ways to work on smaller data samples. This is not an insurmountable limitation of big data sets, but takes some additional work.
> File types: Weka typically prefers Arff files. If you have the time to learn to convert files, you might find the process easier. Typically I now only upload CSV files and have had no problems recently.
> Refreshing data: Once you have applied changes to your data (cleaned fields etc), you will need to upload the data from scratch to return to the original data set.
> Opening the GUI: When you first open Weka, you might find that your computer won’t open from the Icon. This is and easy fix, locate it from the stored location, right click and open from there.
Despite the above, the combination of pre-processing tools, selection of algorithms available and immediate access to visualisations make Weka a fantastic way to get started with machine learning.
Weka is an open source tool that you can download from their website. As mentioned, opening it might be a bit awkward depending on your computer. (See above)
Downloading and installing Weka — Weka Wiki (waikato.github.io)
Once open the ability to upload your data is fairly intuitive, allowing you to import your file. Once open, select ‘Explorer’ to enable you to pre-process and select the features (attributes) you wish to train. Tip: The easiest way to do this is to select the columns you wish to drop, select ‘Invert’ and then delete.
Get ATKims’s stories in your inbox
Join Medium for free to get updates from this writer.
It’s important to normalise numeric columns so that your algorithms can handle the differences in measurement across your attributes. Once you have done this, Weka is a playground for data scientists!!
How do I test the data?
Once you have selected your algorithm, you can choose how to train the data. You can either conduct a number of ‘folds’ , where the data is partitioned and trained one section at a time, or by ‘percentage’ of the data you wish to train. Typically, I get started with 10 folds or 60% data — this is wide open for debate.
Isn’t a higher number of folds better?
To an extent, larger numbers of folds allow greater training opportunities. However, with enough testing you are likely to find a decrease in predictive capability. This is caused by ‘overfitting’, whereby the data has been trained too specifically and the algorithm is working to a tighter set of rules than is helpful, missing the flexibility to account for variation.
Weka has a large collection of machine learning algorithms that can be used for various tasks such as classification, regression, clustering, feature selection, and data pre-processing.
Great, which algorithm should I use?
The available algorithms will depend on exactly what data you have pre-processed. Some are quicker than others and some might not work at all if the data types are incorrect.
To select algorithms, you need to have good knowledge of what machine learning is expected to do with your data. Are you trying to create mathematical clusters? This works well in some survey data. Alternatively you might be applying ‘shopping basket analysis’, understanding consumer behaviours — for this, association rules will be more suitable. Within the type of algorithm you have further choices still, so good research is recommended. If you read my articles you will know I am most interested in geographical work — it can be tricky to select algorithms for geographical data and the pre-processing data requires some creativity!
Here are some algorithms available in Weka:
- Decision Trees: C4.5, J48, Random Forest, and REPTree
- Naive Bayes: NaiveBayes, Multinomial Naive Bayes, and AODE
- Support Vector Machines (SVM): SMO and LibSVM
- Neural Networks: Multilayer Perceptron, Radial Basis Function Network, and IBk neural network
- Clustering: K-Means, DBSCAN, EM, and Hierarchical Clustering
- Association Rules: Apriori and FPGrowth
- Regression: Linear Regression and Logistic Regression
- Feature Selection: GainRatioAttributeEval, ChiSquaredAttributeEval, and Principal Component Analysis (PCA)
There is a large amount of training material available on Weka created by the University of Waikato, the original creators of the tool. This is largely presented in PowerPoint tutorials and covers a wealth of capabilities. You might wish to progress to programming without Weka at a later point, but this is likely to serve you well for a long time to come.









