# How To Use Regression Machine Learning Algorithms in Weka

Weka has a large number of regression algorithms available on the platform.

The large number of machine learning algorithms supported by Weka is one of the biggest benefits of using the platform.

In this post you will discover how to use top regression machine learning algorithms in Weka.

After reading this post you will know:

• About 5 top regression algorithms supported by Weka.
• How to use regression machine learning algorithms for predictive modeling in Weka.
• About the key configuration options of regression algorithms in Weka.

Let’s get started.

How To Use Regression Machine Learning Algorithms in Weka
Photo by solarisgirl, some rights reserved.

## Regression Algorithms Overview

We are going to take a tour of 5 top regression algorithms in Weka.

Each algorithm that we cover will be briefly described in terms of how it works, key algorithm parameters will be highlighted and the algorithm will be demonstrated in the Weka Explorer interface.

The 5 algorithms that we will review are:

1. Linear Regression
2. k-Nearest Neighbors
3. Decision Tree
4. Support Vector Machines
5. Multi-Layer Perceptron

These are 5 algorithms that you can try on your regression problem as a starting point.

A standard machine learning regression problem will be used to demonstrate each algorithm.

Specifically, the Boston House Price Dataset. Each instance describes the properties of a Boston suburb and the task is to predict the house prices in thousands of dollars. There are 13 numerical input variables with varying scales describing the properties of suburbs. You can learn more about this dataset on the UCI Machine Learning Repository.

Start the Weka Explorer:

1. Open the Weka GUI Chooser.
2. Click the “Explorer” button to open the Weka Explorer.
3. Load the Boston house price dataset from the housing.arff file.
4. Click “Classify” to open the Classify tab.

Let’s start things off by looking at the linear regression algorithm.

## Start and Practice Machine Learning With Weka...without writing a single line of code

Weka is the best platform for beginners getting started in applied machine learning.

The graphical user interface and state-of-the-art algorithms makes machine learning fun!

#### Take a FREE 14-Day Mini Course inApplied Machine Learning With Weka

Get your daily lesson via email with tips and tricks.

## Linear Regression

Linear regression only supports regression type problems.

It works by estimating coefficients for a line or hyperplane that best fits the training data. It is a very simple regression algorithm, fast to train and can have great performance if the output variable for your data is a linear combination of your inputs.

It is good idea to evaluate linear regression on your problem before moving onto more complex algorithms in case it performs well.

Choose the linear regression algorithm:

1. Click the “Choose” button and select “LinearRegression” under the “functions” group.
2. Click on the name of the algorithm to review the algorithm configuration.

Weka Configuration of Linear Regression

The performance of linear regression can be reduced if your training data has input attributes that are highly correlated. Weka can detect and remove highly correlated input attributes automatically by setting eliminateColinearAttributes to True, which is the default.

Additionally, attributes that are unrelated to the output variable can also negatively impact performance. Weka can automatically perform feature selection to only select those relevant attributes by setting the attributeSelectionMethod. This is enabled by default and can be disabled.

Finally, the Weka implementation uses a ridge regularization technique in order to reduce the complexity of the learned model. It does this by minimizing the square of the absolute sum of the learned coefficients, which will prevent any specific coefficient from becoming too large (a sign of complexity in regression models).

1. Click “OK” to close the algorithm configuration.
2. Click the “Start” button to run the algorithm on the Boston house price dataset.

You can see that with the default configuration that linear regression achieves an RMSE of 4.9.

Weka Results for Linear Regression

## k-Nearest Neighbors

The k-nearest neighbors algorithm supports both classification and regression. It is also called kNN for short. It works by storing the entire training dataset and querying it to locate the k most similar training patterns when making a prediction.

As such, there is no model other than the raw training dataset and the only computation performed is the querying of the training dataset when a prediction is requested.

It is a simple algorithm, but one that does not assume very much about the problem other than that the distance between data instances is meaningful in making predictions. As such, it often achieves very good performance.

When making predictions on regression problems, KNN will take the mean of the k most similar instances in the training dataset. Choose the KNN algorithm:

1. Click the “Choose” button and select “IBk” under the “lazy” group.
2. Click on the name of the algorithm to review the algorithm configuration.

In Weka KNN is called IBk which stands for Instance Based k.

Weka k-Nearest Neighbors Configuration

The size of the neighborhood is controlled by the k parameter. For example, if set to 1, then predictions are made using the single most similar training instance to a given new pattern for which a prediction is requested. Common values for k are 3, 7, 11 and 21, larger for larger dataset sizes. Weka can automatically discover a good value for k using cross validation inside the algorithm by setting the crossValidate parameter to True.

Another important parameter is the distance measure used. This is configured in the nearestNeighbourSearchAlgorithm which controls the way in which the training data is stored and searched. The default is a LinearNNSearch. Clicking the name of this search algorithm will provide another configuration window where you can choose a distanceFunction parameter. By default, Euclidean distance is used to calculate the distance between instances, which is good for numerical data with the same scale. Manhattan distance is good to use if your attributes differ in measures or type.

It is a good idea to try a suite of different k values and distance measures on your problem and see what works best.

1. Click “OK” to close the algorithm configuration.
2. Click the “Start” button to run the algorithm on the Boston house price dataset.

You can see that with the default configuration that KNN algorithm achieves an RMSE of 4.6.

Weka Regression Results for the k-Nearest Neighbors Algorithm

## Decision Tree

Decision trees can support classification and regression problems.

Decision trees are more recently referred to as Classification And Regression Trees or CART. They work by creating a tree to evaluate an instance of data, start at the root of the tree and moving town to the leaves (roots because the tree is drawn with an inverted prospective) until a prediction can be made. The process of creating a decision tree works by greedily selecting the best split point in order to make predictions and repeating the process until the tree is a fixed depth.

After the tree is construct, it is pruned in order to improve the model’s ability to generalize to new data.

Choose the decision tree algorithm:

1. Click the “Choose” button and select “REPTree” under the “trees” group.
2. Click on the name of the algorithm to review the algorithm configuration.

Weka Configuration for Decision Tree Algorithm

The depth of the tree is defined automatically, but can specify a depth in the maxDepth attribute.

You can also choose to turn off pruning by setting the noPruning parameter to True, although this may result in worse performance.

The minNum parameter defines the minimum number of instances supported by the tree in a leaf node when constructing the tree from the training data.

1. Click “OK” to close the algorithm configuration.
2. Click the “Start” button to run the algorithm on the Boston house price dataset.

You can see that with the default configuration that decision tree algorithm achieves an RMSE of 4.8.

Weka Regression Results for the Decision Tree Algorithm

## Support Vector Regression

Support Vector Machines were developed for binary classification problems, although extensions to the technique have been made to support multi-class classification and regression problems. The adaptation of SVM for regression is called Support Vector Regression or SVR for short.

SVM was developed for numerical input variables, although will automatically convert nominal values to numerical values. Input data is also normalized before being used.

Unlike SVM that finds a line that best separates the training data into classes, SVR works by finding a line of best fit that minimizes the error of a cost function. This is done using an optimization process that only considers those data instances in the training dataset that are closest to the line with the minimum cost. These instances are called support vectors, hence the name of the technique.

In almost all problems of interest, a line cannot be drawn to best fit the data, therefore a margin is added around the line to relax the constraint, allowing some bad predictions to be tolerated but allowing a better result overall.

Finally, few datasets can be fit with just a straight line. Sometimes a line with curves or even polygonal regions need to be marked out. This is achieved by projecting the data into a higher dimensional space in order to draw the lines and make predictions. Different kernels can be used to control the projection and the amount of flexibility.

Choose the SVR algorithm:

1. Click the “Choose” button and select “SMOreg” under the “function” group.
2. Click on the name of the algorithm to review the algorithm configuration.

Weka Configuration for the Support Vector Regression Algorithm

The C parameter, called the complexity parameter in Weka controls how flexible the process for drawing the line to fit the data can be. A value of 0 allows no violations of the margin, whereas the default is 1.

A key parameter in SVM is the type of Kernel to use. The simplest kernel is a Linear kernel that separates data with a straight line or hyperplane. The default in Weka is a Polynomial Kernel that will fit the data using a curved or wiggly line, the higher the polynomial, the more wiggly (the exponent value).

The Polynomial Kernel has a default exponent of 1, which makes it equivalent to a linear kernel. A popular and powerful kernel is the RBF Kernel or Radial Basis Function Kernel that is capable of learning closed polygons and complex shapes to fit the training data.

It is a good idea to try a suite of different kernels and C (complexity) values on your problem and see what works best.

1. Click “OK” to close the algorithm configuration.
2. Click the “Start” button to run the algorithm on the Boston house price dataset.

You can see that with the default configuration that SVR algorithm achieves an RMSE of 5.1.

Weka Regression Results for the Support Vector Regression Algorithm

## Multi-Layer Perceptron

The Multi-Layer Perceptron algorithms supports both regression and classification problems.

It is also called artificial neural networks or simply neural networks for short.

Neural networks are a complex algorithm to use for predictive modeling because there are so many configuration parameters that can only be tuned effectively through intuition and a lot of trial and error.

It is an algorithm inspired by a model of biological neural networks in the brain where small processing units called neurons are organized into layers that if configured well are capable of approximating any function. In classification we are interested in approximating the underlying function to best discriminate between classes. In regression problems we are interested in approximating a function that best fits the real value output.

Choose the Multi-Layer Perceptron algorithm:

1. Click the “Choose” button and select “MultilayerPerceptron” under the “function” group.
2. Click on the name of the algorithm to review the algorithm configuration.

Weka Configuration for the Multi-Layer Perceptron Algorithm

You can manually specify the structure of the neural network that is used by the model, but this is not recommended for beginners.

The default will automatically design the network and train it on your dataset. The default will create a single hidden layer network. You can specify the number of hidden layers in the hiddenLayers parameter, set to automatic “a” by default.

You can also use a GUI to design the network structure. This can be fun, but it is recommended that you use the GUI with a simple train and test split of your training data, otherwise you will be asked to design a network for each of the 10 folds of cross validation.

Weka GUI Designer for the Multi-Layer Perceptron Algorithm

You can configure the learning process by specifying how much to update the model each epoch by setting the learning rate. common values are small such as values between 0.3 (the default) and 0.1.

The learning process can be further tuned with a momentum (set to 0.2 by default) to continue updating the weights even when no changes need to be made, and a decay (set decay to True) which will reduce the learning rate over time to perform more learning at the beginning of training and less at the end.

1. Click “OK” to close the algorithm configuration.
2. Click the “Start” button to run the algorithm on the Boston house price dataset.

You can see that with the default configuration that Multi-Layer Perceptron algorithm achieves an RMSE of 4.7.

Weka Regression Results Multi-Layer Perceptron Algorithm

## Summary

In this post you discovered regression algorithms in Weka.

Specifically you learned:

• About 5 top regression algorithms you can use for predictive modeling.
• How to run regression algorithms in Weka.
• About key configuration options for regression algorithms in Weka.

## Want Machine Learning Without The Code?

#### Develop Your Own Models and Predictions in Minutes

...with just a few a few clicks

Discover how in my new Ebook: Machine Learning Mastery With Weka

It covers self-study tutorials and end-to-end projects on topics like:

### 18 Responses to How To Use Regression Machine Learning Algorithms in Weka

1. Allen August 3, 2016 at 1:20 am #

Hi Jason,

Very appreciate for your hard work on this webpages. I really learn a lot about WEKA from you 😉

Here I have a question about the interpretations of outputs. As we know, the values of both “Mean absolute error” and “Root mean squared error” are expected to be lower which indicates a better value.

However, in my case, “Relative absolute error” and “Root relative squared error” are greater than 100%!!! Is it possible? Are both lower values good as well as MAE/RMSE?

Thank you very much

• Jason Brownlee August 3, 2016 at 8:19 am #

Thanks Allen.

Generally, I would advise you to use Root Mean Square Error, it is just a well understood and well used metric. Only venture out to other measures if the requirements of your problem/domain/etc. force you.

• Allen August 3, 2016 at 9:35 pm #

Can we say “Relative absolute error” and “Root relative squared error” not the important indicators for regression? Or we just overlook them even if they are greater than 100%?

2. Axl October 26, 2016 at 7:49 pm #

Hi Jason,

first of all i want to thank you for these Online Tutorials. They are very useful for me.

My question on this article is: How can you say that these are the top 5 Algortihms? Why not some others? Can you give a statement/reference or something?

Thank you very much

• Jason Brownlee October 27, 2016 at 7:42 am #

These are just algorithms I recommend applying on a problem to get a feeling for what might work and what might not.

It is good to have diversity of algorithm types to help flush out answers to this question.

In general, we cannot know which algorithm will perform best on our problem. If we did, we probably would not need machine learning – we would just solve our problem. That being said, the more you know about your data, the more ideas you get that a given algorithm type or representation might work better than others – but these are just heuristics.

3. Dan H January 16, 2017 at 9:28 am #

Jason, is there a way to set the regularization parameter for the mutlilayer perceptron? This is a fairly common thing to do to make sure the network does not overfit your training data and generalizes well to new data. I’ve been looking in the options for the MultilayerPerceptron class on the Weka Javadoc and I can’t find anything. Any ideas? Thanks for writing this article!

• Jason Brownlee January 16, 2017 at 10:44 am #

Hi Dan,

It looks like this implementation does not have regularization.

4. obafemi joy April 12, 2017 at 5:53 am #

Linear Regression Model

Time taken to build model: 0.04 seconds

=== Evaluation on test set ===

Time taken to test model on supplied test set: 0.02 seconds

=== Summary ===

Correlation coefficient 0.7914
Mean absolute error 0.3449
Root mean squared error 0.4511
Relative absolute error 53.6479 %
Root relative squared error 61.1281 %
Total Number of Instances 84
Ignored Class Unknown Instances 16
how can i interpret this pls

• Jason Brownlee April 12, 2017 at 7:59 am #

Consider just looking at the RMSE (root mean squared error), it is an error that has the same scale as your output variable.

• obafemi joy April 15, 2017 at 8:15 am #

i don’t understand what u mean by RMSE (root mean squared error), it is an error that has the same scale as your output variable. pls can you explain further am new on weka and i need this prediction for my research work thanks man

5. obafemi joy April 17, 2017 at 6:33 am #

thanks man, with the added data this what i get. Am sorry to bother you, with the Linear regression output, is this prediction reliable or not?
Test mode:evaluate on training data

=== Classifier model (full training set) ===

Linear Regression Model

question22a =

0.2423 * qualification +
0.2505 * question5 +
-0.13 * question6 +
-0.1356 * question7 +
-0.1561 * question8a +
-0.0983 * question10a +
0.3403 * question14b +
0.3004 * question16a +
-0.4492 * question16b +
-0.1079 * question17a +
0.1564 * question18a +
-0.1771 * question19b +
-0.2994 * question20b +
0.6329 * question21a +
0.3278 * question22b +
0.5585

Time taken to build model: 0.01 seconds

=== Evaluation on training set ===
=== Summary ===

Correlation coefficient 0.8079
Mean absolute error 0.3358
Root mean squared error 0.4201
Relative absolute error 53.2933 %
Root relative squared error 58.9348 %
Total Number of Instances 88
Ignored Class Unknown Instances 12

• Jason Brownlee April 18, 2017 at 8:27 am #

Consider reviewing the RMSE (root mean squared error), it has the same units as the variable you are predicting.

A skillful RMSE is domain specific, I cannot answer this for you.

6. Dimple April 20, 2017 at 12:09 pm #

Can i have more details of decision trees for regression such as buildiing a model, cross validation and prediction.

7. Abdul Ahad May 25, 2017 at 8:52 am #

I am really appreciate your work. I have actually one question. I work out over linear regression by using data set which gives me appropriate result which i also compared with Ms Excel regression over same data set . The result was same.

Now I want to apply multiple regression. Is Weka Support multiple regression?
Because I search in weka and as well as google but unfortunately i don’t see any appropriate response.

• Jason Brownlee June 2, 2017 at 11:40 am #

Yes, weka supports multiple regression, e.g. multiple input features and one output feature.

8. Rita May 31, 2017 at 12:13 am #

Hello Jason,

I need to apply the models trained in WEKA in a c++ project. Is that possible? If so, how do you suggest that I do it?