{"id":4922,"date":"2023-01-24T07:20:47","date_gmt":"2023-01-24T07:20:47","guid":{"rendered":"https:\/\/unremot.com\/blog\/?p=4922"},"modified":"2023-01-24T07:20:47","modified_gmt":"2023-01-24T07:20:47","slug":"overfitting-and-underfitting-in-machine-learning","status":"publish","type":"post","link":"https:\/\/unremot.com\/blog\/overfitting-and-underfitting-in-machine-learning\/","title":{"rendered":"Overfitting And Underfitting in Machine Learning : A complete guide\u00a0"},"content":{"rendered":"<h2><b>Overfitting and underfitting \u2013 Introduction<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Scientists and developers have made tremendous progress in machine learning and artificial intelligence. Machine learning uses data and algorithms to replicate how humans learn and gradually improves the accuracy of the program. The algorithms produce unsatisfactory results because of overfitting and underfitting. You can improve your model\u2019s performance if you understand why errors occur. In this blog, we explore overfitting and underfitting in machine learning and learn how to avoid them.<\/span><\/p>\n\n<h2><b>What is overfitting in machine learning?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">In this section, we focus on what is overfitting in machine learning. Overfitting is the undesirable tendency in machine learning models that predicts outcomes accurately for training data and not for new data. Data scientist train their models on known data sets before they use them to make predictions. The model tries to make accurate predictions for fresh data sets based on the training or knowledge. An overfit model does not perform for new incoming data and can give inaccurate forecasts.<\/span><\/p>\n<h3><b>What is the catalyst of overfitting?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Before you can learn how to prevent overfitting, it is critical to understand what is the catalyst for overfitting. Overfitting happens when the model cannot generalize but tries to fit too closely with the training dataset. Common causes of overfitting are &#8211;\u00a0<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The data lacks enough samples to represent all possible input data values.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The training data contains a significant amount of irrelevant data or noisy data.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u00a0The model is trained excessively on a single sample data set.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u00a0 \u00a0Because of the high level of complexity involved, the model learns the noise within the training data.<\/span><\/li>\n<\/ul>\n<h3><b>How to improve overfitting in neural networks?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Overfitting in neural network training is a common problem. When you feed new data to the network, the error is much larger than when you use the training set. Although the network has learned the training instances by heart, it has not learned generalization to new circumstances.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Neural networks are susceptible to overfitting because they learn several parameters when creating a model. Due to its substantial capacity, a model with many parameters can overfit the training data.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The network becomes less prone to overfitting by deleting some layers or decreasing the number of neurons since the overfitting-contributing neurons are eliminated or turned off. Because there are fewer parameters for the network to learn, it cannot memorize all the data points and must learn to generalize.<\/span><\/p>\n<p style=\"text-align: center;\"><strong>Also read:\u00a0<a href=\"https:\/\/unremot.com\/blog\/flutter-vs-react-native\/\">Flutter vs react native: A Detailed Comparison with examples<\/a><\/strong><\/p>\n<h3><b>How to reduce overfitting?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Here are some techniques to reduce overfitting<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Train the data more -You can prevent overfitting by training your data. As you input more training data into the model, it will overfit all the data forcing it to generalize to produce results. This method is time-consuming and expensive.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\"><a href=\"https:\/\/www.tensorflow.org\/tutorials\/images\/data_augmentation\" target=\"_blank\" rel=\"noopener\">Data augmentation<\/a> \u2013 Data augmentation causes minor changes every time the model evaluates the data. It prevents the model from learning the properties of the data set and is a more inexpensive option.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Data Simplification \u2013 Overfitting can occur if the model is complicated. Data simplification means decreasing the complexity of the data to ensure it does not overfit. Simplifying the data can also make the model faster.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ensemble \u2013 Ensemble is a machine learning method of combining the prediction of multiple models.<\/span><\/li>\n<\/ul>\n<h3><b>How to avoid overfitting?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Here are some methods on how to avoid overfitting \u2013<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Cross-validation<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Training with more data<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Removing features<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Early stopping the features<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Regularization<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ensembling<\/span><\/li>\n<\/ul>\n<h3><b>How can you detect overfitting?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">The best method to detect overfit models is by testing the machine learning models with more data. You can divide the data into subsets to simplify the training and testing process. Separate the data into two main parts \u2013 testing and training sets. The training set represents about 80% of the data and is responsible for training the model. While the test set is approximately 20% of the data and is used to test the accuracy of the data.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">By segmenting the dataset, you examine the model&#8217;s performance on each dataset to detect overfitting and analyze the effectiveness of the training process. You can measure the accuracy of the two data sets to detect overfitting. The model is probably overfitting if it performs better on the training set than on the test set.<\/span><\/p>\n<p style=\"text-align: center;\"><strong>Also read:\u00a0<a href=\"https:\/\/unremot.com\/blog\/r-vs-python\/\">R vs Python | A complete analysis<\/a><\/strong><\/p>\n<h3><b>Overfitting example<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">In this overfitting example, let us assume you want the model to predict a ball. We provide data input to the model like<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Sphere &#8211; This feature checks if the object is spherical.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u00a0Play &#8211; This checks if one can play with the object.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u00a0Eat &#8211; This checks if one cannot eat it.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Radius = 5 cm -This checks if the radius is 5 cm or less.\u00a0<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Now suppose you show the model a basketball. After checking all the parameters entered, the model will predict the object is not a ball because of the radius parameter.\u00a0<\/span><\/p>\n<h2><b>What is underfitting in machine learning?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Underfitting in machine learning is used to describe a model&#8217;s inability to generalize successfully on the new data because it has not detected or learned patterns in the training data. An underfit model performs poorly on the training set and produces incorrect forecasts. Low variance and high bias lead to underfitting.<\/span><\/p>\n<h3><b>What are the reasons for underfitting?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Reasons for underfitting are \u2013<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u00a0The model is unable to find patterns from the dataset because the dataset contains noise or outliers.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The model exhibits a large bias because of its inability to accurately represent the relationship between input variables and a target value and occurs when there is a varied dataset.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The model considered is too simple.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Incorrect hyperparameters tuning often leads to underfitting due to under-observing of the features.<\/span><\/li>\n<\/ul>\n<h3><b>What are the techniques to correct underfitting?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Some of the techniques to correct underfitting are \u2013<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Increase the complexity of the model.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Increase the number of features in the dataset.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Reduce data noise.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">To get better results, increase the training period or the number of epochs.<\/span><\/li>\n<\/ul>\n<h3><b>How to avoid underfitting?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Here are some ways how to avoid underfitting \u2013<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Increase duration of the training \u2013 If you stop training too soon, you can get an underfit model. You can extend the training duration can prevent underfitting. Remember to find a balance between overtraining and underfitting.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Feature selection \u2013 Select particular features with any model to get specific results. In the absence of predictive features, you need to introduce more features or add more significant features. The model will get more complicated and will improve training outcomes.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Decrease regularization \u2013 You can apply regularization to reduce the variance to a model, by applying a penalty to input parameters with a larger coefficient. You can use several methods such as dropout, L1 regularization, and Lasso regularization to reduce noise and outliers. The model is unable to recognize the dominating trend if the data features become too consistent. Adding more complexity and variety by reducing the amount of regularization, which enables you to train the model successfully.<\/span><\/li>\n<\/ul>\n<p style=\"text-align: center;\"><strong>Also read:\u00a0<a href=\"https:\/\/unremot.com\/blog\/pytorch-vs-tensorflow\/\">\u00a0Pytorch vs TensorFlow\u00a0| Which is the best machine learning framework?<\/a><\/strong><\/p>\n<h3><b>Underfitting example<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Let us continue with the model to predict a ball. In the underfitting model, you trained the model with only one feature the ball is a sphere. The attribute checks if the object has a spherical shape.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now after training the model, you check the model with a lemon. As you told the model anything that is a spherical shape is a ball. It will predict the object is a ball. The model failed because we trained it on fewer data (an under-fit model).<\/span><\/p>\n<h2><b>Overfitting vs underfitting: overview<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Overfitting and underfitting in machine learning are common pitfalls in machine learning that you should avoid. In this section, we look into the difference between overfitting vs underfitting.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Overfitting is an error in deep learning algorithms, where the model tries to match all the training data and ends up retaining the data pattern and noise\/random oscillation. The goal of models is defeated because they do not generalize and perform well in the presence of unforeseen data scenarios.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Underfitting occurs when the model is unable to map the input to the target variable. The inaccuracy in the training and unseen data samples increases when characteristics are not observed fully. Unlike overfitting, which occurs when a model performs well on the training set but fails to transfer its knowledge to the testing set.<\/span><\/p>\n<h2><b>What is a good fit in a statistical model?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">A good fit in a statistical model refers to the quality of the approximation of the target function. This is a great term to use for machine learning because supervised machine learning algorithms aim to estimate the underlying mapping function for the output variables given a set of input variables.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Statisticians frequently employ the goodness of fit, which refers to the metrics used to calculate how closely the function\u2019s approximation matches the target function. The measure of goodness of fit summarizes the discrepancy between the observed value and the expected value for the model being analyzed.<\/span><\/p>\n<h2><b>FAQ: Overfitting and underfitting<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Poor performance in a machine learning model is either because of overfitting or underfitting the data. The goal of machine language models is to generalize well or provide suitable output for a given set of unique inputs. In this section, we focus on some FAQs: overfitting and underfitting.<\/span><\/p>\n<h3><b>What is the catalyst of overfitting?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">The catalyst of overfitting is as follows \u2013<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Training data contains noise or garbage values in it.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The model has high variance.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The size of the training dataset is insufficient.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The model is very complex.<\/span><\/li>\n<\/ul>\n<p style=\"text-align: center;\"><strong>Also read:\u00a0<a href=\"https:\/\/unremot.com\/blog\/best-ethereum-wallets\/\">Top 10 best ethereum wallets | Detail Explanation<\/a><\/strong><\/p>\n<h3><b>What is cross-validation in machine learning?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">The process of cross-validation in machine learning involves training multiple ML models on subsets of input data and comparing the results to the corresponding subset of data to assess the performance of the models. Data scientists use cross-validation to identify overreaching or failing to generalize a pattern. Cross-validation involves the following steps \u2013<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Retain a certain amount of the sample data set.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Train the models by using the remaining data set.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u00a0Use the retained data set to test the model.<\/span><\/li>\n<\/ul>\n<h3><b>What is variance in ML?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Variance in ML refers to the alterations in the model when using different sets in the training data set. Variance is the model\u2019s prediction ability to vary or how much the ML function may change based on the input data set. It occurs when the model is complicated with several features. The model can have high variance low bias or low variance high bias.<\/span><\/p>\n<h3><b>What is Bias?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Bias is a phenomenon that alters the results in favor of or against a certain idea. Bias is seen as a systematic error that occurs in the machine learning model because of false assumptions made during the machine learning process. Technically, we can define bias as the difference between the average model prediction and the actual data. It describes how well the model matches the training set like overfit data has high bias.<\/span><\/p>\n<h3><b>What is noise in machine learning?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Noise refers to the unwanted behavior within the data that provides a low signal-to-noise ratio. Noise can be thought of as errors in the collection of data. Algorithms can misinterpret noise and start generalizing from it. While it is impossible to reduce all noise in a data set, you can reduce it substantially by understanding its cause and correcting them.<\/span><\/p>\n<p style=\"text-align: center;\"><strong>Also read:\u00a0<a href=\"https:\/\/unremot.com\/blog\/how-to-add-avalanche-to-metamask\/\">How to add Avalanche to MetaMask? A quick guide<\/a><\/strong><\/p>\n<h3><b>What is signal processing in machine learning?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">A signal is a method of communicating information and is a mathematical function. Some examples of signals are \u2013 audio, images, ECG, and radar. Electrical engineers use signal processing to model and analyze digital and analog data representations of physical events. Machine learning is seen as an extension of signal processing, where linear processing blocks replace non-linear blocks. This allows users to handle a broader set of problems.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overfitting and underfitting \u2013 Introduction Scientists and developers have made tremendous progress in machine learning and artificial intelligence. Machine learning uses data and algorithms to replicate how humans learn and gradually improves the accuracy of the program. The algorithms produce unsatisfactory results because of overfitting and underfitting. You can improve your model\u2019s performance if you [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":4923,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[78],"tags":[],"class_list":{"0":"post-4922","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-blockchain","8":"entry"},"_links":{"self":[{"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/posts\/4922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/comments?post=4922"}],"version-history":[{"count":2,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/posts\/4922\/revisions"}],"predecessor-version":[{"id":4925,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/posts\/4922\/revisions\/4925"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/media\/4923"}],"wp:attachment":[{"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/media?parent=4922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/categories?post=4922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/tags?post=4922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}