Bias and Variance

Whilst a machine learning model may perform well in its training stage it may not perform well in practice. Whilst a model can learn from data, and should be able to recognise trends within it, it must also strike a good balance between being informed by the data and not overly influenced by it.

The Bias Variance Tradeoff can therefore help data scientists to understand why some models do not perform effectively. It can also show how error can be impacted by model complexity and highlight strategies which can enhance a model’s effectiveness in new scenarios.

Why Do Machine Learning models make errors?

Whilst all models will contain some degree of error, there are various causes. Occasionally a model is not sufficiently advanced to fully comprehend the information it contains. Similarly, a model can become too influenced by its training data and therefore does not sufficiently generalise.

To illustrate – an e-commerce business may wish to analyse consumer behaviour. A rudimentary model could be based solely on people’s age and so would not take into account a person’s web activity, buying behaviour or favourite goods, along with seasonal influences. Conversely, an overly sophisticated model may begin to recognise spurious trends within past data which are not particularly useful to the business.

Appreciating these issues involves understanding both bias and variance within a model.

What is model bias?

Model bias reflects the error which occurs due to incorrect assumptions about the link between inputs and outputs.

Highly biased models tend to be too basic and so do not effectively demonstrate the trends in a dataset. This is often described as underfitting.

Suppose we wanted to create a model that could estimate a household’s energy usage per month. We know that house occupancy will impact a household’s energy needs. However, energy consumption is also affected by factors including weather conditions, the type of appliances within a house and personal behaviour. If a model does not consider these influences then it may repeatedly provide flawed estimations.

Contributory factors to a model’s bias can be:

• An inappropriate choice of learning algorithm;

• Failure to incorporate key variables;

• Over regularisation of a model;

• Believing that a trend is linear whereas it in fact has a non-linear nature;

• Poor training and/or unsuitable variables.

Typically, high bias leads to sub-optimal model functioning on both training and validation data.

Counteracting high bias can involve adding suitable variables, utilising a more sophisticated learning algorithm and/or reviewing a model’s assumptions.

What is model variance?

Model variance demonstrates how predictions vary between different training data samples derived from the same dataset.

High variance is typically indicative of overfitting. Rather than recognising overarching trends, a model becomes disproportionately influenced by specific data points and also by noise.

Continuing our previous example, suppose a decision tree is used to determine whether a customer is likely to re-subscribe to a service. Should the decision tree become excessively detailed, it may start to replicate particular customer behaviours. However, when new customers are added to the system these finely tuned rules may then become ineffective.

Typical sources of high variance are:

• An overly sophisticated model;

• Limited training data;

• Too numerous and/or unsuitable variables;

• A lack of regularisation;

• Poor validation processes.

Simplifying models, ensuring that training data is adequately representative and implementing cross-validation can all be effective ways of managing variance. Furthermore, decision trees can themselves be pruned.

Bias Variance Tradeoff

This concept highlights that the most sophisticated model is not necessarily the most effective.

Whilst less complex models may exhibit high bias, they often contain reduced variance. Conversely, highly adaptable models can have reduced bias, but may also display heightened variance as they are more responsive to variations in the training data.

An optimal solution will thus usually exist which enables a model to effectively recognise trends and also to reliably generalise.

Below is a summary of differing model characteristics:

Model characteristic Bias Variance Outcome

Underfitting High Typically low Fails to spot significant trends

Well balanced Controlled Controlled Good generalisation

Overfitting Frequently low High Incorporates noise and is overly influenced by data

It is also crucial to recognise that in addition to model error, there is also inherent noise that cannot always be eradicated purely by changing the model. Such noise arises due to the uncertain and/or random nature of data.

How to effectively manage bias and variance

As noted above, there is no single ideal model for all data sets. Data scientists investigate and test various algorithms and modify their parameters. They also assess how models function using different data samples.

There are a number of approaches which can be adopted.

1. Cross-validation

Cross-validation partitions data into separate sections. Models are then trained and tested using varying groupings of these sections. This can therefore assist in gauging how reliably a model generalises.

2. Regularisation

Regularisation (L1 and L2) involves adding a cost element which encourages model variables to remain of a reasonable scale. It can thus help to avoid undue reliance on particular variables.

3. Controlling model complexity

Many machine learning algorithms, such as decision trees, support vector machines and neural networks, contain controllable elements which alter their adaptability. Appropriate hyperparameters can be determined through tuning in order to secure a good balance between a model’s learning ability and its generalisation.

4. Studying learning curves

Learning curves graphically display a model’s training and validation effectiveness as training data increases. Considerable divergence between these results can point to overfitting. Conversely, if both metrics continue to perform poorly then underfitting may be occurring.

5. Enhancing data

Poor data can negatively affect models. Issues may arise in relation to missing and/or conflicting data and the inclusion of irrelevant variables. Additionally, data sampling can present difficulties. Refining data and ensuring that the training data set is well representative can therefore enhance the reliability of model assessment.

Real world applications

Bias variance analysis is applicable in many areas where machine learning is used. Within healthcare, models must recognise significant trends and yet not become over-reliant on a small patient data set. Financial institutions require models to detect fraudulent activity but must also ensure that they do not raise an unwarranted high level of false alarms. Likewise, retailers’ recommendation tools should discern consumer inclinations, rather than merely replicating prior customer behaviour.

Such analysis can therefore enable data experts to competently assess these situations and further inform their decision making relating to model choice, training and optimisation.

Putting theory into practice

Alongside theoretical comprehension, it is valuable to put this into practice. Aspiring data scientists can utilise Python packages such as Scikit-learn to explore regression, decision trees, ensemble modelling and validation.

Practical application also allows people to appreciate how data processing, variable consideration and assessment all contribute to model predictive efficacy.

NIDADS specialises in providing work-focused data science, data analytics and AI education. It also incorporates practical projects to ensure that theoretical topics can be related to relevant industry contexts.

Conclusion

Whilst low training error is important in constructing an effective machine learning model, it is also essential to appreciate how models respond to new information.

The Bias Variance Tradeoff can effectively be used to recognise under- and over-fitting and generalisation issues. By appropriately selecting models, including suitable regularisation, employing cross-validation and utilising quality data, data scientists can therefore construct more reliably functioning predictive models.

Categorized in:

Tagged in: