<?xml version="1.0" encoding="utf-8" ?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:tt="http://teletype.in/" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"><title>@asadbek_universe</title><author><name>@asadbek_universe</name></author><id>https://teletype.in/atom/asadbek_universe</id><link rel="self" type="application/atom+xml" href="https://teletype.in/atom/asadbek_universe?offset=0"></link><link rel="alternate" type="text/html" href="https://teletype.in/@asadbek_universe?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=asadbek_universe"></link><link rel="next" type="application/rss+xml" href="https://teletype.in/atom/asadbek_universe?offset=10"></link><link rel="search" type="application/opensearchdescription+xml" title="Teletype" href="https://teletype.in/opensearch.xml"></link><updated>2026-04-20T06:36:37.815Z</updated><entry><id>asadbek_universe:AucRoc</id><link rel="alternate" type="text/html" href="https://teletype.in/@asadbek_universe/AucRoc?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=asadbek_universe"></link><title>Learning curves (AUC ROC curve)</title><published>2023-01-04T08:57:57.495Z</published><updated>2023-01-04T08:58:17.522Z</updated><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img1.teletype.in/files/0e/44/0e446079-4640-4a9b-b1b5-964ce7ff2304.png"></media:thumbnail><summary type="html">&lt;img src=&quot;https://static.javatpoint.com/tutorial/machine-learning/images/auc-roc-curve-in-machine-learning.png&quot;&gt;Learning curves are plots used to show a model's performance as the training set size increases. Another way it can be used is to show the model's performance over a defined period of time. We typically used them to diagnose algorithms that learn incrementally from data. It works by evaluating a model on the training and validation datasets, then plotting the measured performance.</summary><content type="html">
  &lt;p id=&quot;Qews&quot;&gt;Learning curves are plots used to show a model&amp;#x27;s performance as the training set size increases. Another way it can be used is to show the model&amp;#x27;s performance over a defined period of time. We typically used them to diagnose algorithms that learn incrementally from data. It works by evaluating a model on the training and validation datasets, then plotting the measured performance.&lt;/p&gt;
  &lt;p id=&quot;ZPsa&quot;&gt;In Machine Learning, only developing an ML model is not sufficient as we also need to see whether it is performing well or not. It means that after building an ML model, we need to evaluate and validate how good or bad it is, and for such cases, we use different Evaluation Metrics. &lt;em&gt;AUC-ROC curve is such an evaluation metric that is used to visualize the performance of a classification model&lt;/em&gt;.&lt;/p&gt;
  &lt;h3 id=&quot;mikr&quot;&gt;ROC Curve&lt;/h3&gt;
  &lt;p id=&quot;c9kw&quot;&gt;&lt;strong&gt;&lt;em&gt;ROC or Receiver Operating Characteristic curve represents a probability graph to show the performance of a classification model at different threshold levels&lt;/em&gt;&lt;/strong&gt;. The curve is plotted between two parameters, which are:&lt;/p&gt;
  &lt;ul id=&quot;oWeO&quot;&gt;
    &lt;li id=&quot;Ywne&quot;&gt;&lt;strong&gt;True Positive Rate or TPR&lt;/strong&gt;&lt;/li&gt;
    &lt;li id=&quot;9NbD&quot;&gt;&lt;strong&gt;False Positive Rate or FPR&lt;/strong&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p id=&quot;S4aj&quot;&gt;In the curve, TPR is plotted on Y-axis, whereas FPR is on the X-axis.&lt;/p&gt;
  &lt;h3 id=&quot;dicV&quot;&gt;TPR:&lt;/h3&gt;
  &lt;p id=&quot;7mA5&quot;&gt;TPR or True Positive rate is a synonym for Recall, which can be calculated as:&lt;/p&gt;
  &lt;figure id=&quot;kKYj&quot; class=&quot;m_original&quot;&gt;
    &lt;img src=&quot;https://static.javatpoint.com/tutorial/machine-learning/images/auc-roc-curve-in-machine-learning.png&quot; width=&quot;503&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;ABll&quot;&gt;FPR or False Positive Rate can be calculated as:&lt;/p&gt;
  &lt;figure id=&quot;Vj4d&quot; class=&quot;m_original&quot;&gt;
    &lt;img src=&quot;https://static.javatpoint.com/tutorial/machine-learning/images/auc-roc-curve-in-machine-learning2.png&quot; width=&quot;401&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;f0hX&quot;&gt;Here, &lt;strong&gt;TP&lt;/strong&gt;: True Positive&lt;/p&gt;
  &lt;p id=&quot;kmXr&quot;&gt;&lt;strong&gt;FP&lt;/strong&gt;: False Positive&lt;/p&gt;
  &lt;p id=&quot;47FT&quot;&gt;&lt;strong&gt;TN&lt;/strong&gt;: True Negative&lt;/p&gt;
  &lt;p id=&quot;gjy7&quot;&gt;&lt;strong&gt;FN&lt;/strong&gt;: False Negative&lt;/p&gt;
  &lt;p id=&quot;fetc&quot;&gt;Now, to efficiently calculate the values at any threshold level, we need a method, which is AUC.&lt;/p&gt;
  &lt;h3 id=&quot;gjob&quot;&gt;AUC: Area Under the ROC curve&lt;/h3&gt;
  &lt;p id=&quot;4gRS&quot;&gt;AUC is known for &lt;strong&gt;Area Under the ROC curve&lt;/strong&gt;. As its name suggests, AUC calculates the two-dimensional area under the entire ROC curve ranging from (0,0) to (1,1), as shown below image:&lt;/p&gt;
  &lt;figure id=&quot;KQLV&quot; class=&quot;m_original&quot;&gt;
    &lt;img src=&quot;https://static.javatpoint.com/tutorial/machine-learning/images/auc-roc-curve-in-machine-learning3.png&quot; width=&quot;400&quot; /&gt;
    &lt;figcaption&gt;https://www.javatpoint.com/auc-roc-curve-in-machine-learning&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;uG7k&quot;&gt;In the ROC curve, AUC computes the performance of the binary classifier across different thresholds and provides an aggregate measure. The value of AUC ranges from 0 to 1, which means an excellent model will have AUC near 1, and hence it will show a good measure of Separability.&lt;/p&gt;
  &lt;h3 id=&quot;Vs8R&quot;&gt;When to Use AUC-ROC&lt;/h3&gt;
  &lt;p id=&quot;C9S2&quot;&gt;&lt;strong&gt;AUC is preferred due to the following cases:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul id=&quot;L8Rq&quot;&gt;
    &lt;li id=&quot;xAby&quot;&gt;AUC is used to measure how well the predictions are ranked instead of giving their absolute values. Hence, we can say AUC is &lt;strong&gt;Scale-Invariant.&lt;/strong&gt;&lt;/li&gt;
    &lt;li id=&quot;PX9k&quot;&gt;It measures the quality of predictions of the model without considering the selected classification threshold. It means AUC is &lt;strong&gt;classification-threshold-invariant.&lt;/strong&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;h3 id=&quot;se0E&quot;&gt;When not to use AUC-ROC&lt;/h3&gt;
  &lt;ul id=&quot;6ONS&quot;&gt;
    &lt;li id=&quot;G2KS&quot;&gt;AUC is not preferable when we need to calibrate probability output.&lt;/li&gt;
    &lt;li id=&quot;bOrL&quot;&gt;Further, AUC is not a useful metric when there are wide disparities in the cost of false negatives vs false positives, and it is difficult to minimize one type of classification error.&lt;/li&gt;
  &lt;/ul&gt;
  &lt;figure id=&quot;1Nla&quot; class=&quot;m_column&quot;&gt;
    &lt;iframe src=&quot;https://www.youtube.com/embed/4jRBRDbJemM?autoplay=0&amp;loop=0&amp;mute=0&quot;&gt;&lt;/iframe&gt;
    &lt;figcaption&gt;https://www.youtube.com/@statquest&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;h2 id=&quot;Zfs8&quot;&gt;References&lt;/h2&gt;
  &lt;p id=&quot;9wkp&quot;&gt;The main article - &lt;a href=&quot;https://www.javatpoint.com/auc-roc-curve-in-machine-learning&quot; target=&quot;_blank&quot;&gt;https://www.javatpoint.com/auc-roc-curve-in-machine-learning&lt;/a&gt;&lt;/p&gt;
  &lt;p id=&quot;42q0&quot;&gt;The video explanation - &lt;a href=&quot;https://www.youtube.com/watch?v=4jRBRDbJemM&amp;list=PLblh5JKOoLUICTaGLRoHQDuF_7q2GfuJF&amp;index=12&quot; target=&quot;_blank&quot;&gt;https://www.youtube.com/watch?v=4jRBRDbJemM&amp;amp;list=PLblh5JKOoLUICTaGLRoHQDuF_7q2GfuJF&amp;amp;index=12&lt;/a&gt;&lt;/p&gt;

</content></entry><entry><id>asadbek_universe:RegularizationTechniques</id><link rel="alternate" type="text/html" href="https://teletype.in/@asadbek_universe/RegularizationTechniques?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=asadbek_universe"></link><title>Regularization Techniques</title><published>2023-01-04T08:30:36.655Z</published><updated>2023-01-04T08:30:36.655Z</updated><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img2.teletype.in/files/57/0e/570eaccb-66cb-46d3-b5d9-9f6585fdc7dd.png"></media:thumbnail><summary type="html">&lt;img src=&quot;https://miro.medium.com/max/568/1*DY3-IaGcHjjLg7oYXx1O3A.png&quot;&gt;From the articles of geeksforgeeks.org and javatpoint.com we have a look at overall information about regularization and it's types. After that we have a visual explanations in videos of the YouTube channel StatQuest with Josh Starmer. At the end we explore the article published in Towards Data Science by Prashant Gupta.</summary><content type="html">
  &lt;h2 id=&quot;Xi57&quot;&gt;Introduction&lt;/h2&gt;
  &lt;p id=&quot;Via5&quot;&gt;From the articles of &lt;a href=&quot;https://www.geeksforgeeks.org/&quot; target=&quot;_blank&quot;&gt;geeksforgeeks.org&lt;/a&gt; and &lt;a href=&quot;https://www.javatpoint.com/&quot; target=&quot;_blank&quot;&gt;javatpoint.com&lt;/a&gt; we have a look at overall information about regularization and it&amp;#x27;s types. After that we have a visual explanations in videos of the YouTube channel &lt;a href=&quot;https://www.youtube.com/@statquest&quot; target=&quot;_blank&quot;&gt;StatQuest with Josh Starmer&lt;/a&gt;. At the end we explore the article published in &lt;a href=&quot;https://towardsdatascience.com/&quot; target=&quot;_blank&quot;&gt;Towards Data Science&lt;/a&gt; by Prashant Gupta.&lt;/p&gt;
  &lt;h1 id=&quot;G8rx&quot;&gt;Regularization in Machine Learning&lt;/h1&gt;
  &lt;p id=&quot;F5y5&quot;&gt;&lt;em&gt;Regularization&lt;/em&gt; is a technique used to reduce the errors by fitting the function appropriately on the given training set and avoid overfitting. &lt;/p&gt;
  &lt;p id=&quot;7wyM&quot;&gt;Sometimes the machine learning model performs well with the training data but does not perform well with the test data. It means the model is not able to predict the output when deals with unseen data by introducing noise in the output, and hence the model is called overfitted. This problem can be deal with the help of a regularization technique.&lt;/p&gt;
  &lt;p id=&quot;GB6W&quot;&gt;This technique can be used in such a way that it will allow to maintain all variables or features in the model by reducing the magnitude of the variables. Hence, it maintains accuracy as well as a generalization of the model.&lt;/p&gt;
  &lt;p id=&quot;0mWX&quot;&gt;It mainly regularizes or reduces the coefficient of features toward zero. In simple words, &amp;quot;&lt;em&gt;In regularization technique, we reduce the magnitude of the features by keeping the same number of features.&amp;quot;&lt;/em&gt;&lt;/p&gt;
  &lt;p id=&quot;bhTy&quot;&gt;The commonly used regularization techniques are :&lt;/p&gt;
  &lt;ul id=&quot;oUbH&quot;&gt;
    &lt;li id=&quot;3sal&quot;&gt;L1 regularization&lt;/li&gt;
    &lt;li id=&quot;PUMk&quot;&gt;L2 regularization&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p id=&quot;6fdJ&quot;&gt;A regression model that uses &lt;strong&gt;L2 regularization&lt;/strong&gt; technique is called &lt;strong&gt;Ridge regression&lt;/strong&gt;.&lt;/p&gt;
  &lt;figure id=&quot;hZyt&quot; class=&quot;m_column&quot;&gt;
    &lt;iframe src=&quot;https://www.youtube.com/embed/Q81RR3yKn30?autoplay=0&amp;loop=0&amp;mute=0&quot;&gt;&lt;/iframe&gt;
    &lt;figcaption&gt;https://www.youtube.com/@statquest&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;cCqh&quot;&gt;A regression model which uses &lt;strong&gt;L1 Regularization &lt;/strong&gt;technique is called &lt;strong&gt;LASSO(Least Absolute Shrinkage and Selection Operator)&lt;/strong&gt; regression&lt;/p&gt;
  &lt;figure id=&quot;FdZ7&quot; class=&quot;m_column&quot;&gt;
    &lt;iframe src=&quot;https://www.youtube.com/embed/NGf0voTMlcs?autoplay=0&amp;loop=0&amp;mute=0&quot;&gt;&lt;/iframe&gt;
    &lt;figcaption&gt;https://www.youtube.com/@statquest&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;blockquote id=&quot;jjg2&quot;&gt;More visual explanations about Regularization you can find in the playlist &lt;a href=&quot;https://youtube.com/playlist?list=PLblh5JKOoLUICTaGLRoHQDuF_7q2GfuJF&quot; target=&quot;_blank&quot;&gt;https://youtube.com/playlist?list=PLblh5JKOoLUICTaGLRoHQDuF_7q2GfuJF&lt;/a&gt;&lt;/blockquote&gt;
  &lt;h1 id=&quot;8541&quot;&gt;Regularization in Machine Learning II&lt;/h1&gt;
  &lt;p id=&quot;4e23&quot;&gt;One of the major aspects of training your machine learning model is avoiding overfitting. &lt;em&gt;The model will have a low accuracy if it is overfitting.&lt;/em&gt; This happens because your model is trying too hard to capture the noise in your training dataset. &lt;strong&gt;&lt;em&gt;By noise we mean the data points that don’t really represent the true properties of your data, but random chance&lt;/em&gt;&lt;/strong&gt;. Learning such data points, makes your model more flexible, at the risk of overfitting.&lt;/p&gt;
  &lt;p id=&quot;42f4&quot;&gt;&lt;strong&gt;&lt;em&gt;The concept of balancing bias and variance, is helpful in understanding the phenomenon of overfitting.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;h3 id=&quot;KoOf&quot;&gt;Balancing Bias and Variance to Control Errors in Machine Learning&lt;/h3&gt;
  &lt;blockquote id=&quot;Kc5S&quot;&gt;One of the ways of avoiding overfitting is using cross validation, that helps in estimating the error over test set, and in deciding what parameters work best for your model.&lt;/blockquote&gt;
  &lt;p id=&quot;6afe&quot;&gt;This article will focus on a technique that helps in avoiding overfitting and also increasing model interpretability.&lt;/p&gt;
  &lt;h2 id=&quot;581e&quot;&gt;Regularization&lt;/h2&gt;
  &lt;p id=&quot;7042&quot;&gt;This is a form of regression, that constrains/ regularizes or shrinks the coefficient estimates towards zero. In other words, &lt;strong&gt;&lt;em&gt;this technique discourages learning a more complex or flexible model, so as to avoid the risk of overfitting.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;p id=&quot;cc32&quot;&gt;A simple relation for linear regression looks like this. Here Y represents the learned relation and &lt;em&gt;β represents the coefficient estimates for different variables or predictors(X).&lt;/em&gt;&lt;/p&gt;
  &lt;p id=&quot;ad05&quot;&gt;&lt;strong&gt;&lt;em&gt;Y ≈ β0 + β1X1 + β2X2 + …+ βpXp&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;p id=&quot;2776&quot;&gt;The fitting procedure involves a loss function, known as residual sum of squares or RSS. The coefficients are chosen, such that they minimize this loss function.&lt;/p&gt;
  &lt;figure id=&quot;FzS9&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/568/1*DY3-IaGcHjjLg7oYXx1O3A.png&quot; width=&quot;454&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;22b5&quot;&gt;Now, this will adjust the coefficients based on your training data. &lt;em&gt;If there is noise in the training data, then the estimated coefficients won’t generalize well to the future data. This is where regularization comes in and shrinks or regularizes these learned estimates towards zero.&lt;/em&gt;&lt;/p&gt;
  &lt;h2 id=&quot;d7cb&quot;&gt;Ridge Regression&lt;/h2&gt;
  &lt;figure id=&quot;IWuO&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/691/1*CiqZ8lhwxi5c4d1nV24w4g.png&quot; width=&quot;553&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;be62&quot;&gt;Above image shows ridge regression, where the &lt;em&gt;RSS is modified by adding the shrinkage quantity.&lt;/em&gt; Now, the coefficients are estimated by minimizing this function. Here, &lt;em&gt;λ is the tuning parameter that decides how much we want to penalize the flexibility of our model.&lt;/em&gt; The increase in flexibility of a model is represented by increase in its coefficients, and if we want to minimize the above function, then these coefficients need to be small. This is how the Ridge regression technique prevents coefficients from rising too high. Also, notice that we shrink the estimated association of each variable with the response, except the intercept β0, This intercept is a measure of the mean value of the response when xi1 = xi2 = …= xip = 0.&lt;/p&gt;
  &lt;p id=&quot;e35c&quot;&gt;&lt;em&gt;When λ = 0, the penalty term has no eﬀect&lt;/em&gt;, and the estimates produced by ridge regression will be equal to least squares. However, &lt;em&gt;as λ→∞, the impact of the shrinkage penalty grows, and the ridge regression coeﬃcient estimates will approach zero&lt;/em&gt;. As can be seen, selecting a good value of λ is critical. Cross validation comes in handy for this purpose. The coefficient estimates produced by this method are &lt;em&gt;also known as the L2 norm&lt;/em&gt;.&lt;/p&gt;
  &lt;p id=&quot;d992&quot;&gt;&lt;em&gt;The coefficients that are produced by the standard least squares method are scale equivariant&lt;/em&gt;, i.e. if we multiply each input by c then the corresponding coefficients are scaled by a factor of 1/c. Therefore, regardless of how the predictor is scaled, the multiplication of predictor and coefficient(Xjβj) remains the same. &lt;em&gt;However, this is not the case with ridge regression, and therefore, we need to standardize the predictors or bring the predictors to the same scale before performing ridge regression&lt;/em&gt;. The formula used to do this is given below.&lt;/p&gt;
  &lt;figure id=&quot;d6mS&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/351/1*6KRAdbf-CApFPR7gASZaSA.png&quot; width=&quot;281&quot; /&gt;
  &lt;/figure&gt;
  &lt;h2 id=&quot;ada5&quot;&gt;Lasso&lt;/h2&gt;
  &lt;figure id=&quot;WYPv&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/684/1*tHJ4sSPYV0bDr8xxEdiwXA.png&quot; width=&quot;547&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;c8da&quot;&gt;Lasso is another variation, in which the above function is minimized. Its clear that &lt;em&gt;this variation differs from ridge regression only in penalizing the high coefficients&lt;/em&gt;. It uses |βj|(modulus)instead of squares of β, as its penalty. In statistics, this is&lt;strong&gt;&lt;em&gt; known as the L1 norm&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;
  &lt;p id=&quot;6bd5&quot;&gt;Lets take a look at above methods with a different perspective. &lt;em&gt;The ridge regression can be thought of as solving an equation, where summation of squares of coefficients is less than or equal to s&lt;/em&gt;. And &lt;em&gt;the Lasso can be thought of as an equation where summation of modulus of coefficients is less than or equal to s&lt;/em&gt;. Here, s is a constant that exists for each value of shrinkage factor &lt;em&gt;λ. These equations are also referred to as constraint functions.&lt;/em&gt;&lt;/p&gt;
  &lt;p id=&quot;8821&quot;&gt;&lt;em&gt;Consider their are 2 parameters in a given problem&lt;/em&gt;. Then according to above formulation, the &lt;strong&gt;&lt;em&gt;ridge regression is expressed by β1² + β2² ≤ s&lt;/em&gt;&lt;/strong&gt;. This implies that &lt;em&gt;ridge regression coefficients have the smallest RSS(loss function) for all points that lie within the circle given by β1² + β2² ≤ s.&lt;/em&gt;&lt;/p&gt;
  &lt;p id=&quot;7cd3&quot;&gt;Similarly, &lt;strong&gt;&lt;em&gt;for lasso, the equation becomes,|β1|+|β2|≤ s&lt;/em&gt;&lt;/strong&gt;. This implies that &lt;em&gt;lasso coefficients have the smallest RSS(loss function) for all points that lie within the diamond given by |β1|+|β2|≤ s.&lt;/em&gt;&lt;/p&gt;
  &lt;p id=&quot;ba7c&quot;&gt;The image below describes these equations.&lt;/p&gt;
  &lt;figure id=&quot;QWRI&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/875/1*XC-8tHoMxrO3ogHKylRfRA.png&quot; width=&quot;700&quot; /&gt;
    &lt;figcaption&gt;Credit : An Introduction to Statistical Learning by Gareth James, Daniela Witten, Trevor Hastie, Robert Tibshirani&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;eed3&quot;&gt;&lt;em&gt;The above image shows the constraint functions(green areas), for lasso(left) and ridge regression(right), along with contours for RSS(red ellipse)&lt;/em&gt;. Points on the ellipse share the value of RSS. For a very large value of s, the green regions will contain the center of the ellipse, making coefficient estimates of both regression techniques, equal to the least squares estimates. But, this is not the case in the above image. In this case, the lasso and ridge regression coefficient estimates are given by the ﬁrst point at which an ellipse contacts the constraint region. &lt;em&gt;Since ridge regression has a circular constraint with no sharp points, this intersection will not generally occur on an axis, and so the ridge regression coeﬃcient estimates will be exclusively non-zero.&lt;/em&gt; &lt;em&gt;However, the lasso constraint has corners at each of the axes, and so the ellipse will often intersect the constraint region at an axis. When this occurs, one of the coeﬃcients will equal zero&lt;strong&gt;.&lt;/strong&gt;&lt;/em&gt; In higher dimensions(where parameters are much more than 2), many of the coeﬃcient estimates may equal zero simultaneously.&lt;/p&gt;
  &lt;p id=&quot;3707&quot;&gt;This sheds light on the obvious disadvantage of ridge regression, which is model interpretability. It will shrink the coefficients for least important predictors, very close to zero. But it will never make them exactly zero. In other words, the final model will include all predictors. However, in the case of the lasso, the L1 penalty has the eﬀect of forcing some of the coeﬃcient estimates to be exactly equal to zero when the tuning parameter λ is suﬃciently large. &lt;strong&gt;Therefore, the lasso method also performs variable selection and is said to yield sparse models.&lt;/strong&gt;&lt;/p&gt;
  &lt;h3 id=&quot;c646&quot;&gt;What does Regularization achieve?&lt;/h3&gt;
  &lt;p id=&quot;f798&quot;&gt;A standard least squares model tends to have some variance in it, i.e. this model won’t generalize well for a data set different than its training data. &lt;em&gt;Regularization, significantly reduces the variance of the model, without substantial increase in its bias&lt;/em&gt;. So the tuning parameter λ, used in the regularization techniques described above, controls the impact on bias and variance. As the value of λ rises, it reduces the value of coefficients and thus reducing the variance. &lt;em&gt;Till a point, this increase in λ is beneficial as it is only reducing the variance(hence avoiding overfitting), without loosing any important properties in the data.&lt;/em&gt; But after certain value, the model starts loosing important properties, giving rise to bias in the model and thus underfitting. Therefore, the value of λ should be carefully selected.&lt;/p&gt;
  &lt;h2 id=&quot;HWWe&quot;&gt;References&lt;/h2&gt;
  &lt;p id=&quot;QQY7&quot;&gt;The Articles:&lt;/p&gt;
  &lt;ul id=&quot;3WDx&quot;&gt;
    &lt;li id=&quot;9ORV&quot;&gt;&lt;a href=&quot;https://www.geeksforgeeks.org/regularization-in-machine-learning/&quot; target=&quot;_blank&quot;&gt;https://www.geeksforgeeks.org/regularization-in-machine-learning/&lt;/a&gt;&lt;/li&gt;
    &lt;li id=&quot;3iqr&quot;&gt;&lt;a href=&quot;https://www.javatpoint.com/regularization-in-machine-learning&quot; target=&quot;_blank&quot;&gt;https://www.javatpoint.com/regularization-in-machine-learning&lt;/a&gt;&lt;/li&gt;
    &lt;li id=&quot;ePGp&quot;&gt;&lt;a href=&quot;https://towardsdatascience.com/regularization-in-machine-learning-76441ddcf99a&quot; target=&quot;_blank&quot;&gt;https://towardsdatascience.com/regularization-in-machine-learning-76441ddcf99a&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p id=&quot;udQ5&quot;&gt;Video Explanations:&lt;/p&gt;
  &lt;ul id=&quot;HfBY&quot;&gt;
    &lt;li id=&quot;Ie7B&quot;&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Q81RR3yKn30&amp;list=PLblh5JKOoLUICTaGLRoHQDuF_7q2GfuJF&amp;index=23&quot; target=&quot;_blank&quot;&gt;https://www.youtube.com/watch?v=Q81RR3yKn30&amp;amp;list=PLblh5JKOoLUICTaGLRoHQDuF_7q2GfuJF&amp;amp;index=23&lt;/a&gt;&lt;/li&gt;
    &lt;li id=&quot;0kO7&quot;&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=NGf0voTMlcs&amp;list=PLblh5JKOoLUICTaGLRoHQDuF_7q2GfuJF&amp;index=24&quot; target=&quot;_blank&quot;&gt;https://www.youtube.com/watch?v=NGf0voTMlcs&amp;amp;list=PLblh5JKOoLUICTaGLRoHQDuF_7q2GfuJF&amp;amp;index=24&lt;/a&gt;&lt;/li&gt;
    &lt;li id=&quot;QWWu&quot;&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Xm2C_gTAl8c&amp;list=PLblh5JKOoLUICTaGLRoHQDuF_7q2GfuJF&amp;index=25&quot; target=&quot;_blank&quot;&gt;https://www.youtube.com/watch?v=Xm2C_gTAl8c&amp;amp;list=PLblh5JKOoLUICTaGLRoHQDuF_7q2GfuJF&amp;amp;index=25&lt;/a&gt;&lt;/li&gt;
    &lt;li id=&quot;IOft&quot;&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=1dKRdX9bfIo&amp;list=PLblh5JKOoLUICTaGLRoHQDuF_7q2GfuJF&amp;index=26&quot; target=&quot;_blank&quot;&gt;https://www.youtube.com/watch?v=1dKRdX9bfIo&amp;amp;list=PLblh5JKOoLUICTaGLRoHQDuF_7q2GfuJF&amp;amp;index=26&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;

</content></entry><entry><id>asadbek_universe:LogisticRegression</id><link rel="alternate" type="text/html" href="https://teletype.in/@asadbek_universe/LogisticRegression?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=asadbek_universe"></link><title>Logistic Regression</title><published>2023-01-04T07:51:26.606Z</published><updated>2023-01-04T08:35:18.129Z</updated><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img1.teletype.in/files/87/12/8712d1d2-d2e2-4358-90f9-83f6343d1196.png"></media:thumbnail><summary type="html">&lt;img src=&quot;https://static.javatpoint.com/tutorial/machine-learning/images/logistic-regression-in-machine-learning.png&quot;&gt;Let's have a quick overall information given in one of the articles of javatpoint.com, after which we have a video from StatQuest with Josh Starmer, then we will go through  article with detailed overview published in Towards Data Science by Saishruthi Swaminathan.</summary><content type="html">
  &lt;h2 id=&quot;ZmNZ&quot;&gt;Introduction&lt;/h2&gt;
  &lt;p id=&quot;irxm&quot;&gt;Let&amp;#x27;s have a quick overall information given in one of the articles of javatpoint.com, after which we have a video from StatQuest with Josh Starmer, then we will go through  article with detailed overview published in Towards Data Science by Saishruthi Swaminathan.&lt;/p&gt;
  &lt;h1 id=&quot;u8Kx&quot;&gt;Logistic Regression in Machine Learning&lt;/h1&gt;
  &lt;ul id=&quot;RnU5&quot;&gt;
    &lt;li id=&quot;ojMi&quot;&gt;Logistic regression is one of the most popular Machine Learning algorithms, which comes under the Supervised Learning technique. It is used for predicting the categorical dependent variable using a given set of independent variables.&lt;/li&gt;
    &lt;li id=&quot;tAAh&quot;&gt;Logistic regression predicts the output of a categorical dependent variable. Therefore the outcome must be a categorical or discrete value. It can be either Yes or No, 0 or 1, true or False, etc. but instead of giving the exact value as 0 and 1, &lt;strong&gt;it gives the probabilistic values which lie between 0 and 1&lt;/strong&gt;.&lt;/li&gt;
    &lt;li id=&quot;W1I0&quot;&gt;Logistic Regression is much similar to the Linear Regression except that how they are used. Linear Regression is used for solving Regression problems, whereas &lt;strong&gt;Logistic regression is used for solving the classification problems&lt;/strong&gt;.&lt;/li&gt;
    &lt;li id=&quot;o1dl&quot;&gt;In Logistic regression, instead of fitting a regression line, we fit an &amp;quot;S&amp;quot; shaped logistic function, which predicts two maximum values (0 or 1).&lt;/li&gt;
    &lt;li id=&quot;fTHe&quot;&gt;The curve from the logistic function indicates the likelihood of something such as whether the cells are cancerous or not, a mouse is obese or not based on its weight, etc.&lt;/li&gt;
    &lt;li id=&quot;oZVB&quot;&gt;Logistic Regression is a significant machine learning algorithm because it has the ability to provide probabilities and classify new data using continuous and discrete datasets.&lt;/li&gt;
    &lt;li id=&quot;gGnW&quot;&gt;Logistic Regression can be used to classify the observations using different types of data and can easily determine the most effective variables used for the classification. The below image is showing the logistic function:&lt;/li&gt;
  &lt;/ul&gt;
  &lt;figure id=&quot;Xoiq&quot; class=&quot;m_original&quot;&gt;
    &lt;img src=&quot;https://static.javatpoint.com/tutorial/machine-learning/images/logistic-regression-in-machine-learning.png&quot; width=&quot;500&quot; /&gt;
    &lt;figcaption&gt;https://www.javatpoint.com/logistic-regression-in-machine-learning&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;figure id=&quot;LqOr&quot; class=&quot;m_column&quot;&gt;
    &lt;iframe src=&quot;https://www.youtube.com/embed/yIYKR4sgzI8?autoplay=0&amp;loop=0&amp;mute=0&quot;&gt;&lt;/iframe&gt;
    &lt;figcaption&gt;https://www.youtube.com/@statquest&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;h1 id=&quot;0331&quot;&gt;Logistic Regression — Detailed Overview&lt;/h1&gt;
  &lt;p id=&quot;731f&quot;&gt;Logistic Regression was used in the biological sciences in early twentieth century. It was then used in many social science applications. Logistic Regression is used when the dependent variable(target) is categorical.&lt;/p&gt;
  &lt;p id=&quot;87e6&quot;&gt;For example,&lt;/p&gt;
  &lt;ul id=&quot;Kst7&quot;&gt;
    &lt;li id=&quot;395b&quot;&gt;To predict whether an email is spam (1) or (0)&lt;/li&gt;
    &lt;li id=&quot;059b&quot;&gt;Whether the tumor is malignant (1) or not (0)&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p id=&quot;065d&quot;&gt;Consider a scenario where we need to classify whether an email is spam or not. If we use linear regression for this problem, there is a need for setting up a threshold based on which classification can be done. Say if the actual class is malignant, predicted continuous value 0.4 and the threshold value is 0.5, the data point will be classified as not malignant which can lead to serious consequence in real time.&lt;/p&gt;
  &lt;p id=&quot;b360&quot;&gt;From this example, it can be inferred that linear regression is not suitable for classification problem. Linear regression is unbounded, and this brings logistic regression into picture. Their value strictly ranges from 0 to 1.&lt;/p&gt;
  &lt;p id=&quot;76e8&quot;&gt;&lt;strong&gt;Simple Logistic Regression&lt;/strong&gt;&lt;/p&gt;
  &lt;p id=&quot;6bab&quot;&gt;(Full Source code: &lt;a href=&quot;https://github.com/SSaishruthi/LogisticRegression_Vectorized_Implementation/blob/master/Logistic_Regression.ipynb&quot; target=&quot;_blank&quot;&gt;https://github.com/SSaishruthi/LogisticRegression_Vectorized_Implementation/blob/master/Logistic_Regression.ipynb&lt;/a&gt;)&lt;/p&gt;
  &lt;p id=&quot;f8a5&quot;&gt;&lt;strong&gt;&lt;em&gt;Model&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;p id=&quot;d8b4&quot;&gt;Output = 0 or 1&lt;/p&gt;
  &lt;p id=&quot;00b3&quot;&gt;Hypothesis =&amp;gt; Z = WX + B&lt;/p&gt;
  &lt;p id=&quot;9348&quot;&gt;hΘ(x) = sigmoid (Z)&lt;/p&gt;
  &lt;p id=&quot;e792&quot;&gt;&lt;strong&gt;&lt;em&gt;Sigmoid Function&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;figure id=&quot;Se4v&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/875/1*RqXFpiNGwdiKBWyLJc_E7g.png&quot; width=&quot;700&quot; /&gt;
    &lt;figcaption&gt;Figure 2: Sigmoid Activation Function&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;07ab&quot;&gt;If ‘Z’ goes to infinity, Y(predicted) will become 1 and if ‘Z’ goes to negative infinity, Y(predicted) will become 0.&lt;/p&gt;
  &lt;p id=&quot;1eb5&quot;&gt;&lt;strong&gt;&lt;em&gt;Analysis of the hypothesis&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;p id=&quot;64e2&quot;&gt;The output from the hypothesis is the estimated probability. This is used to infer how confident can predicted value be actual value when given an input X. Consider the below example,&lt;/p&gt;
  &lt;p id=&quot;2e5c&quot;&gt;X = [x0 x1] = [1 IP-Address]&lt;/p&gt;
  &lt;p id=&quot;c3d8&quot;&gt;Based on the x1 value, let’s say we obtained the estimated probability to be 0.8. This tells that there is 80% chance that an email will be spam.&lt;/p&gt;
  &lt;p id=&quot;bfa0&quot;&gt;Mathematically this can be written as,&lt;/p&gt;
  &lt;figure id=&quot;eZkG&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/685/1*i_QQvUzXCETJEelf4mLx8Q.png&quot; width=&quot;548&quot; /&gt;
    &lt;figcaption&gt;Figure 3: Mathematical Representation&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;874b&quot;&gt;This justifies the name ‘logistic regression’. Data is fit into linear regression model, which then be acted upon by a logistic function predicting the target categorical dependent variable.&lt;/p&gt;
  &lt;p id=&quot;4007&quot;&gt;&lt;strong&gt;&lt;em&gt;Types of Logistic Regression&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;p id=&quot;df74&quot;&gt;1. Binary Logistic Regression&lt;/p&gt;
  &lt;p id=&quot;4844&quot;&gt;The categorical response has only two 2 possible outcomes. Example: Spam or Not&lt;/p&gt;
  &lt;p id=&quot;8c22&quot;&gt;2. Multinomial Logistic Regression&lt;/p&gt;
  &lt;p id=&quot;d2a6&quot;&gt;Three or more categories without ordering. Example: Predicting which food is preferred more (Veg, Non-Veg, Vegan)&lt;/p&gt;
  &lt;p id=&quot;0ce1&quot;&gt;3. Ordinal Logistic Regression&lt;/p&gt;
  &lt;p id=&quot;d827&quot;&gt;Three or more categories with ordering. Example: Movie rating from 1 to 5&lt;/p&gt;
  &lt;p id=&quot;5834&quot;&gt;&lt;strong&gt;&lt;em&gt;Decision Boundary&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;p id=&quot;4303&quot;&gt;To predict which class a data belongs, a threshold can be set. Based upon this threshold, the obtained estimated probability is classified into classes.&lt;/p&gt;
  &lt;p id=&quot;daac&quot;&gt;Say, if predicted_value ≥ 0.5, then classify email as spam else as not spam.&lt;/p&gt;
  &lt;p id=&quot;d477&quot;&gt;Decision boundary can be linear or non-linear. Polynomial order can be increased to get complex decision boundary.&lt;/p&gt;
  &lt;p id=&quot;30ed&quot;&gt;&lt;strong&gt;&lt;em&gt;Cost Function&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;figure id=&quot;gpEn&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/623/1*TqZ9myxIdLuKNmt8orCeew.png&quot; width=&quot;498&quot; /&gt;
    &lt;figcaption&gt;Figure 4: Cost Function of Logistic Regression&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;260d&quot;&gt;Why cost function which has been used for linear can not be used for logistic?&lt;/p&gt;
  &lt;p id=&quot;226d&quot;&gt;Linear regression uses mean squared error as its cost function. If this is used for logistic regression, then it will be a non-convex function of parameters (theta). Gradient descent will converge into global minimum only if the function is convex.&lt;/p&gt;
  &lt;figure id=&quot;ajKR&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/579/1*ZyjEj3A_QyR4WY7y5cwIWQ.png&quot; width=&quot;463&quot; /&gt;
    &lt;figcaption&gt;Figure 5: Convex and non-convex cost function&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;8f5a&quot;&gt;&lt;strong&gt;&lt;em&gt;Cost function explanation&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;figure id=&quot;94jE&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/875/1*5AYaGPV-gjYUf37d2IhgTQ.jpeg&quot; width=&quot;700&quot; /&gt;
    &lt;figcaption&gt;Figure 6: Cost Function part 1&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;figure id=&quot;iAQK&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/875/1*MFMIEUC_dobhJrRjGK7PBg.jpeg&quot; width=&quot;700&quot; /&gt;
    &lt;figcaption&gt;Figure 7: Cost Function part 2&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;532f&quot;&gt;&lt;strong&gt;&lt;em&gt;Simplified cost function&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;figure id=&quot;O6QT&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/875/1*ueEwU1dE0Yu-KpMJanf9AQ.png&quot; width=&quot;700&quot; /&gt;
    &lt;figcaption&gt;Figure 8: Simplified Cost Function&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;40cd&quot;&gt;&lt;strong&gt;&lt;em&gt;Why this cost function?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;figure id=&quot;Vi9D&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/875/1*heGae4aZ-dN-rLsfx2-P9g.jpeg&quot; width=&quot;700&quot; /&gt;
    &lt;figcaption&gt;Figure 9: Maximum Likelihood Explanation part-1&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;figure id=&quot;DegL&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/875/1*JIpaau-jFfvX2yR9L1YZ6A.jpeg&quot; width=&quot;700&quot; /&gt;
    &lt;figcaption&gt;Figure 10: Maximum Likelihood Explanation part-2&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;6727&quot;&gt;This negative function is because when we train, we need to maximize the probability by minimizing loss function. Decreasing the cost will increase the maximum likelihood assuming that samples are drawn from an identically independent distribution.&lt;/p&gt;
  &lt;p id=&quot;776e&quot;&gt;&lt;strong&gt;&lt;em&gt;Deriving the formula for Gradient Descent Algorithm&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;figure id=&quot;rjJm&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/875/1*r7fhk417IOuq7meXIctGXg.jpeg&quot; width=&quot;700&quot; /&gt;
    &lt;figcaption&gt;Figure 11: Gradient Descent Algorithm part 1&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;figure id=&quot;EzMF&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/875/1*pJEi5f4gdVGezYev9MChBw.jpeg&quot; width=&quot;700&quot; /&gt;
    &lt;figcaption&gt;Figure 12: Gradient Descent part 2&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;5f8f&quot;&gt;&lt;strong&gt;&lt;em&gt;Python Implementation&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;pre id=&quot;m7WX&quot;&gt;def weightInitialization(n_features):
    w = np.zeros((1,n_features))
    b = 0
    return w,b
def sigmoid_activation(result):
    final_result = 1/(1+np.exp(-result))
    return final_result
    
def model_optimize(w, b, X, Y):
    m = X.shape[0]
    
    #Prediction
    final_result = sigmoid_activation(np.dot(w,X.T)+b)
    Y_T = Y.T
    cost = (-1/m)*(np.sum((Y_T*np.log(final_result)) + ((1-Y_T)*(np.log(1-final_result)))))
    
    #Gradient calculation
    dw = (1/m)*(np.dot(X.T, (final_result-Y.T).T))
    db = (1/m)*(np.sum(final_result-Y.T))
    
    grads = {&amp;quot;dw&amp;quot;: dw, &amp;quot;db&amp;quot;: db}
    
    return grads, cost
def model_predict(w, b, X, Y, learning_rate, no_iterations):
    costs = []
    for i in range(no_iterations):
        grads, cost = model_optimize(w,b,X,Y)
        dw = grads[&amp;quot;dw&amp;quot;]
        db = grads[&amp;quot;db&amp;quot;]
        #weight update
        w = w - (learning_rate * (dw.T))
        b = b - (learning_rate * db)
       
        if (i % 100 == 0):
            costs.append(cost)
            #print(&amp;quot;Cost after %i iteration is %f&amp;quot; %(i, cost))
       
        #final parameters
        coeff = {&amp;quot;w&amp;quot;: w, &amp;quot;b&amp;quot;: b}
        gradient = {&amp;quot;dw&amp;quot;: dw, &amp;quot;db&amp;quot;: db}
       
        return coeff, gradient, costs
       
def predict(final_pred, m):
    y_pred = np.zeros((1,m))
    for i in range(final_pred.shape[1]):
        if final_pred[0][i] &amp;gt; 0.5:
            y_pred[0][i] = 1
    return y_pred&lt;/pre&gt;
  &lt;p id=&quot;73dc&quot;&gt;Cost vs Number_of_Iterations&lt;/p&gt;
  &lt;figure id=&quot;UA7z&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/778/1*uRaeTkF5Ig_DYZwR8HiJMQ.png&quot; width=&quot;622&quot; /&gt;
    &lt;figcaption&gt;Figure 13: Cost Reduction&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;bc19&quot;&gt;Train and test accuracy of the system is 100 %&lt;/p&gt;
  &lt;p id=&quot;5ca6&quot;&gt;This implementation is for binary logistic regression. For data with more than 2 classes, softmax regression has to be used.&lt;/p&gt;
  &lt;h2 id=&quot;dQpJ&quot;&gt;References&lt;/h2&gt;
  &lt;p id=&quot;jbqG&quot;&gt;The article about Logistic Regression - &lt;a href=&quot;https://www.javatpoint.com/logistic-regression-in-machine-learning&quot; target=&quot;_blank&quot;&gt;https://www.javatpoint.com/logistic-regression-in-machine-learning&lt;/a&gt;&lt;/p&gt;
  &lt;p id=&quot;Lmef&quot;&gt;The video about Logistic Regression - &lt;a href=&quot;https://www.youtube.com/watch?v=yIYKR4sgzI8&quot; target=&quot;_blank&quot;&gt;https://www.youtube.com/watch?v=yIYKR4sgzI8&lt;/a&gt;&lt;/p&gt;
  &lt;p id=&quot;X9Ge&quot;&gt;The main post about Logistic Regression - &lt;a href=&quot;https://towardsdatascience.com/logistic-regression-detailed-overview-46c4da4303bc&quot; target=&quot;_blank&quot;&gt;https://towardsdatascience.com/logistic-regression-detailed-overview-46c4da4303bc&lt;/a&gt;&lt;/p&gt;
  &lt;p id=&quot;sTR3&quot;&gt;Additional Info - &lt;a href=&quot;https://www.ibm.com/topics/logistic-regression#:~:text=Resources-,What%20is%20logistic%20regression%3F,given%20dataset%20of%20independent%20variables&quot; target=&quot;_blank&quot;&gt;https://www.ibm.com/topics/logistic-regression#:~:text=Resources-,What%20is%20logistic%20regression%3F,given%20dataset%20of%20independent%20variables&lt;/a&gt;.&lt;/p&gt;
  &lt;p id=&quot;Rwme&quot;&gt;The Source Code - &lt;a href=&quot;https://github.com/SSaishruthi/LogisticRegression_Vectorized_Implementation/blob/master/Logistic_Regression.ipynb&quot; target=&quot;_blank&quot;&gt;https://github.com/SSaishruthi/LogisticRegression_Vectorized_Implementation/blob/master/Logistic_Regression.ipynb&lt;/a&gt;&lt;/p&gt;

</content></entry><entry><id>asadbek_universe:LinearRegression</id><link rel="alternate" type="text/html" href="https://teletype.in/@asadbek_universe/LinearRegression?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=asadbek_universe"></link><title>Linear Regression</title><published>2023-01-04T06:59:11.802Z</published><updated>2023-01-04T06:59:11.802Z</updated><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img3.teletype.in/files/a3/67/a36789f9-bc15-4324-8aca-67fe20c91de7.png"></media:thumbnail><summary type="html">&lt;img src=&quot;https://miro.medium.com/max/1400/1*Cw5ZSYDkIFpmhBwr-hN84A.png&quot;&gt;We begin to dive into the world of actual Machine Learning starting from this topic. There are few techniques of ML: Supervised Learning, Unsupervised Learning, Reinforcement Learning and Semi-supervised Learning. And Linear Regression is one of the bases of &quot;Supervised Learning&quot; techniques.</summary><content type="html">
  &lt;h3 id=&quot;TcaY&quot;&gt;&lt;em&gt;Foreword&lt;/em&gt;&lt;/h3&gt;
  &lt;p id=&quot;5UBs&quot;&gt;&lt;em&gt;We begin to dive into the world of actual &lt;strong&gt;Machine Learning&lt;/strong&gt; starting from this topic. There are few techniques of ML: Supervised Learning, Unsupervised Learning, Reinforcement Learning and Semi-supervised Learning. And &lt;strong&gt;Linear Regression&lt;/strong&gt; is one of the bases of &amp;quot;Supervised Learning&amp;quot; techniques.&lt;/em&gt;&lt;/p&gt;
  &lt;h2 id=&quot;5ItZ&quot;&gt;What is Linear Regression?&lt;/h2&gt;
  &lt;p id=&quot;Szyv&quot;&gt;Linear regression is a model that assumes a relationship between the independent(x) variables and one dependent(y) variable. It performs the task to predict a dependent(y) variable value based on a given independent(x) variable. Simple linear regression is a type of linear regression where there is single independent(x) variable.&lt;/p&gt;
  &lt;figure id=&quot;V72b&quot; class=&quot;m_column&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/1400/1*Cw5ZSYDkIFpmhBwr-hN84A.png&quot; width=&quot;1400&quot; /&gt;
    &lt;figcaption&gt;https://miro.medium.com&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;Ymn1&quot;&gt;Let us understand the principle of the regression model visually with the help of a video published in channel &lt;a href=&quot;https://www.youtube.com/@statquest&quot; target=&quot;_blank&quot;&gt;StatQuest with Josh Starmer&lt;/a&gt;&lt;/p&gt;
  &lt;figure id=&quot;kzwB&quot; class=&quot;m_column&quot;&gt;
    &lt;iframe src=&quot;https://www.youtube.com/embed/nk2CQITm_eo?autoplay=0&amp;loop=0&amp;mute=0&quot;&gt;&lt;/iframe&gt;
    &lt;figcaption&gt;https://www.youtube.com/watch?v=nk2CQITm_eo&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;MqvA&quot;&gt;Now let&amp;#x27;s have a look at the post published in Towards Data Science by &lt;em&gt;Rohith Gandhi &lt;/em&gt;&lt;/p&gt;
  &lt;pre id=&quot;tToJ&quot;&gt;y = a_0 + a_1 * x ## Linear Equation&lt;/pre&gt;
  &lt;p id=&quot;gkge&quot;&gt;The motive of the linear regression algorithm is to find the best values for a_0 and a_1. Before moving on to the algorithm, let’s have a look at two important concepts you must know to better understand linear regression.&lt;/p&gt;
  &lt;h2 id=&quot;0bwQ&quot;&gt;Cost Function&lt;/h2&gt;
  &lt;p id=&quot;W8c0&quot;&gt;The cost function helps us to figure out the best possible values for a_0 and a_1 which would provide the best fit line for the data points. Since we want the best values for a_0 and a_1, we convert this search problem into a minimization problem where we would like to minimize the error between the predicted value and the actual value.&lt;/p&gt;
  &lt;figure id=&quot;7sqo&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/608/1*wQCSNJ486WxL4mZ3FOYtgw.png&quot; width=&quot;486&quot; /&gt;
    &lt;figcaption&gt;Minimization and Cost Function&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;ZrQk&quot;&gt;We choose the above function to minimize. The difference between the predicted values and ground truth measures the error difference. We square the error difference and sum over all data points and divide that value by the total number of data points. This provides the average squared error over all the data points. Therefore, this cost function is also known as the Mean Squared Error(MSE) function. Now, using this MSE function we are going to change the values of a_0 and a_1 such that the MSE value settles at the minima.&lt;/p&gt;
  &lt;h2 id=&quot;7ajY&quot;&gt;Gradient Descent&lt;/h2&gt;
  &lt;p id=&quot;Faxf&quot;&gt;The next important concept needed to understand linear regression is gradient descent. Gradient descent is a method of updating a_0 and a_1 to reduce the cost function(MSE). The idea is that we start with some values for a_0 and a_1 and then we change these values iteratively to reduce the cost. Gradient descent helps us on how to change the values.&lt;/p&gt;
  &lt;figure id=&quot;djW2&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/proxy/0*QwE8M4MupSdqA3M4.png&quot; width=&quot;700&quot; /&gt;
    &lt;figcaption&gt;Gradient Descent&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;J3mw&quot;&gt;To draw an analogy, imagine a pit in the shape of U and you are standing at the topmost point in the pit and your objective is to reach the bottom of the pit. There is a catch, you can only take a discrete number of steps to reach the bottom. If you decide to take one step at a time you would eventually reach the bottom of the pit but this would take a longer time. If you choose to take longer steps each time, you would reach sooner but, there is a chance that you could overshoot the bottom of the pit and not exactly at the bottom. In the gradient descent algorithm, the number of steps you take is the learning rate. This decides on how fast the algorithm converges to the minima.&lt;/p&gt;
  &lt;figure id=&quot;v6ti&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/579/0*GrBkYv2vodl_swFI.png&quot; width=&quot;463&quot; /&gt;
    &lt;figcaption&gt;Convex vs Non-convex function&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;3K1M&quot;&gt;Sometimes the cost function can be a non-convex function where you could settle at a local minima but for linear regression, it is always a convex function.&lt;/p&gt;
  &lt;p id=&quot;cs8v&quot;&gt;You may be wondering how to use gradient descent to update a_0 and a_1. To update a_0 and a_1, we take gradients from the cost function. To find these gradients, we take partial derivatives with respect to a_0 and a_1. Now, to understand how the partial derivatives are found below you would require some calculus but if you don’t, it is alright. You can take it as it is.&lt;/p&gt;
  &lt;figure id=&quot;yCqz&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/1423/1*D4Q7zeRBmZ3z1CbD37CIhg.png&quot; width=&quot;470&quot; /&gt;
  &lt;/figure&gt;
  &lt;figure id=&quot;OJUi&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://miro.medium.com/max/708/1*fr-f6K1ebanMA4Roz8JENA.png&quot; width=&quot;531&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;rKto&quot;&gt;The partial derivates are the gradients and they are used to update the values of a_0 and a_1. Alpha is the learning rate which is a hyperparameter that you must specify. A smaller learning rate could get you closer to the minima but takes more time to reach the minima, a larger learning rate converges sooner but there is a chance that you could overshoot the minima.&lt;/p&gt;
  &lt;blockquote id=&quot;MUlH&quot;&gt;The article is very well written, I advice you to visit at the end &lt;a href=&quot;https://towardsdatascience.com/introduction-to-machine-learning-algorithms-linear-regression-14c4e325882a&quot; target=&quot;_blank&quot;&gt;https://towardsdatascience.com/introduction-to-machine-learning-algorithms-linear-regression-14c4e325882a&lt;/a&gt;&lt;/blockquote&gt;
  &lt;p id=&quot;TMXF&quot;&gt;As I guess, video explanation would make a better picture. The ML video-tutorial from &lt;a href=&quot;https://www.youtube.com/@codebasics&quot; target=&quot;_blank&quot;&gt;codebasics&lt;/a&gt; would be suitable for our topic.&lt;/p&gt;
  &lt;figure id=&quot;5Ndh&quot; class=&quot;m_column&quot;&gt;
    &lt;iframe src=&quot;https://www.youtube.com/embed/vsWrXfO3wWw?autoplay=0&amp;loop=0&amp;mute=0&quot;&gt;&lt;/iframe&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;3obp&quot;&gt;The code from the video:&lt;/p&gt;
  &lt;pre id=&quot;TLdG&quot;&gt;import numpy as np

def gradient_descent(x,y):
    m_curr = b_curr = 0
    iterations = 10000
    n = len(x)
    learning_rate = 0.08

    for i in range(iterations):
        y_predicted = m_curr * x + b_curr
        cost = (1/n) * sum([val**2 for val in (y-y_predicted)])
        md = -(2/n)*sum(x*(y-y_predicted))
        bd = -(2/n)*sum(y-y_predicted)
        m_curr = m_curr - learning_rate * md
        b_curr = b_curr - learning_rate * bd
        print (&amp;quot;m {}, b {}, cost {} iteration {}&amp;quot;.format(m_curr,b_curr,cost, i))

x = np.array([1,2,3,4,5])
y = np.array([5,7,9,11,13])

gradient_descent(x,y)&lt;/pre&gt;
  &lt;p id=&quot;y5yz&quot;&gt;&lt;/p&gt;
  &lt;h3 id=&quot;ZbwA&quot;&gt;References&lt;/h3&gt;
  &lt;p id=&quot;EaSs&quot;&gt;&lt;a href=&quot;https://towardsdatascience.com/introduction-to-machine-learning-algorithms-linear-regression-14c4e325882a&quot; target=&quot;_blank&quot;&gt;https://towardsdatascience.com/introduction-to-machine-learning-algorithms-linear-regression-14c4e325882a&lt;/a&gt;&lt;/p&gt;
  &lt;p id=&quot;5FwG&quot;&gt;&lt;a href=&quot;https://machinelearningmastery.com/linear-regression-for-machine-learning/&quot; target=&quot;_blank&quot;&gt;https://machinelearningmastery.com/linear-regression-for-machine-learning/&lt;/a&gt;&lt;/p&gt;
  &lt;p id=&quot;fKto&quot;&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=vsWrXfO3wWw&quot; target=&quot;_blank&quot;&gt;https://www.youtube.com/watch?v=vsWrXfO3wWw&lt;/a&gt;&lt;/p&gt;
  &lt;p id=&quot;Vxbt&quot;&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nk2CQITm_eo&quot; target=&quot;_blank&quot;&gt;https://www.youtube.com/watch?v=nk2CQITm_eo&lt;/a&gt;&lt;/p&gt;

</content></entry><entry><id>asadbek_universe:OverfittingUnderfitting</id><link rel="alternate" type="text/html" href="https://teletype.in/@asadbek_universe/OverfittingUnderfitting?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=asadbek_universe"></link><title>Overfitting/Underfitting</title><published>2023-01-04T06:45:18.434Z</published><updated>2023-01-04T06:52:54.437Z</updated><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img2.teletype.in/files/9a/0d/9a0dfb21-272a-4f1d-be3f-8b99bd18c97b.png"></media:thumbnail><summary type="html">&lt;img src=&quot;https://static.javatpoint.com/tutorial/machine-learning/images/overfitting-and-underfitting.png&quot;&gt;So, we started to explore Supervised Learning. Let's have a bit understanding of approximating a target function (f) that maps input variables (X) to an output variable (Y)</summary><content type="html">
  &lt;p id=&quot;anmq&quot;&gt;So, we started to explore Supervised Learning. Let&amp;#x27;s have a bit understanding of approximating a target function (f) that maps input variables (X) to an output variable (Y)&lt;/p&gt;
  &lt;pre id=&quot;NUaR&quot;&gt; Y = f(X)&lt;/pre&gt;
  &lt;p id=&quot;oSov&quot;&gt;This characterization describes the range of classification and prediction problems and the machine algorithms that can be used to address them. An important consideration in learning the target function from the training data is how well the model generalizes to new data.&lt;/p&gt;
  &lt;blockquote id=&quot;257L&quot;&gt;&lt;a href=&quot;https://machinelearningmastery.com/overfitting-and-underfitting-with-machine-learning-algorithms/&quot; target=&quot;_blank&quot;&gt;https://machinelearningmastery.com/overfitting-and-underfitting-with-machine-learning-algorithms/&lt;/a&gt;&lt;/blockquote&gt;
  &lt;h2 id=&quot;6bp7&quot;&gt;Generalization in Machine Learning&lt;/h2&gt;
  &lt;p id=&quot;dxKn&quot;&gt;&lt;em&gt;Gneralization&lt;/em&gt; defines the ability of an ML model to provide a suitable output by adapting the given set of unknown input. It means after providing training on the dataset, it can produce reliable and accurate output. Hence, the underfitting and overfitting are the two terms that need to be checked for the performance of the model and whether the model is generalizing well or not.&lt;/p&gt;
  &lt;p id=&quot;K0l9&quot;&gt;Before understanding the overfitting and underfitting, let&amp;#x27;s understand some basic term that will help to understand this topic well:&lt;/p&gt;
  &lt;ul id=&quot;luMH&quot;&gt;
    &lt;li id=&quot;scC6&quot;&gt;&lt;strong&gt;Signal:&lt;/strong&gt; It refers to the true underlying pattern of the data that helps the machine learning model to learn from the data.&lt;/li&gt;
    &lt;li id=&quot;HPyj&quot;&gt;&lt;strong&gt;Noise:&lt;/strong&gt; Noise is unnecessary and irrelevant data that reduces the performance of the model.&lt;/li&gt;
    &lt;li id=&quot;28I7&quot;&gt;&lt;strong&gt;Bias: &lt;/strong&gt;Assumptions made by a model to make a function easier to learn. It is actually the error rate of the training data. When the error rate has a high value, we call it High Bias and when the error rate has a low value, we call it low Bias.&lt;/li&gt;
    &lt;li id=&quot;kcoJ&quot;&gt;&lt;strong&gt;Variance: &lt;/strong&gt; The difference between the error rate of training data and testing data is called variance. If the difference is high then it’s called high variance and when the difference of errors is low then it’s called low variance. Usually, we want to make a low variance for generalized our model.&lt;/li&gt;
  &lt;/ul&gt;
  &lt;blockquote id=&quot;bv5m&quot;&gt;&lt;a href=&quot;https://www.javatpoint.com/overfitting-and-underfitting-in-machine-learning#:~:text=Underfitting%20occurs%20when%20our%20machine,enough%20from%20the%20training%20data&quot; target=&quot;_blank&quot;&gt;https://www.javatpoint.com/overfitting-and-underfitting-in-machine-learning#:~:text=Underfitting%20occurs%20when%20our%20machine,enough%20from%20the%20training%20data&lt;/a&gt;.&lt;/blockquote&gt;
  &lt;h2 id=&quot;hpes&quot;&gt;Overfitting&lt;/h2&gt;
  &lt;p id=&quot;8JYG&quot;&gt;Overfitting occurs when our machine learning model tries to cover all the data points or more than the required data points present in the given dataset. Because of this, the model starts caching noise and inaccurate values present in the dataset, and all these factors reduce the efficiency and accuracy of the model.&lt;/p&gt;
  &lt;p id=&quot;DZuy&quot;&gt;The chances of occurrence of overfitting increase as much we provide training to our model. It means the more we train our model, the more chances of occurring the overfitted model.&lt;/p&gt;
  &lt;figure id=&quot;rxmv&quot; class=&quot;m_original&quot;&gt;
    &lt;img src=&quot;https://static.javatpoint.com/tutorial/machine-learning/images/overfitting-and-underfitting.png&quot; width=&quot;550&quot; /&gt;
    &lt;figcaption&gt;https://www.javatpoint.com&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;njev&quot;&gt;* Overfitting is the main problem that occurs in supervised learning.&lt;/p&gt;
  &lt;p id=&quot;95Ti&quot;&gt;Reasons for Overfitting:&lt;/p&gt;
  &lt;ul id=&quot;QYv7&quot;&gt;
    &lt;li id=&quot;TIQ3&quot;&gt;High variance and low bias&lt;/li&gt;
    &lt;li id=&quot;Zn99&quot;&gt;The model is too complex&lt;/li&gt;
    &lt;li id=&quot;TcOY&quot;&gt;The size of the training data&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p id=&quot;GY5m&quot;&gt;Techniques to reduce overfitting:&lt;/p&gt;
  &lt;ul id=&quot;o7d4&quot;&gt;
    &lt;li id=&quot;6IE9&quot;&gt;Increase training data&lt;/li&gt;
    &lt;li id=&quot;FotP&quot;&gt;Reduce model complexity&lt;/li&gt;
    &lt;li id=&quot;n2q0&quot;&gt;Early stopping during the training phase (have an eye over the loss over the training period as soon as loss begins to increase stop training)&lt;/li&gt;
    &lt;li id=&quot;lLV7&quot;&gt;Other techniques (take a look if you are interested: &amp;quot;8 Simple Techniques to Prevent Overfitting&amp;quot; - &lt;a href=&quot;https://towardsdatascience.com/8-simple-techniques-to-prevent-overfitting-4d443da2ef7d&quot; target=&quot;_blank&quot;&gt;https://towardsdatascience.com/8-simple-techniques-to-prevent-overfitting-4d443da2ef7d&lt;/a&gt;)&lt;/li&gt;
  &lt;/ul&gt;
  &lt;h2 id=&quot;pTIi&quot;&gt;Underfitting&lt;/h2&gt;
  &lt;p id=&quot;AyGx&quot;&gt;Underfitting occurs when our machine learning model is not able to capture the underlying trend of the data. To avoid the overfitting in the model, the fed of training data can be stopped at an early stage, due to which the model may not learn enough from the training data. As a result, it may fail to find the best fit of the dominant trend in the data.&lt;/p&gt;
  &lt;p id=&quot;S5bu&quot;&gt;In the case of underfitting, the model is not able to learn enough from the training data, and hence it reduces the accuracy and produces unreliable predictions.&lt;/p&gt;
  &lt;figure id=&quot;U3N6&quot; class=&quot;m_original&quot;&gt;
    &lt;img src=&quot;https://static.javatpoint.com/tutorial/machine-learning/images/overfitting-and-underfitting2.png&quot; width=&quot;500&quot; /&gt;
    &lt;figcaption&gt;https://www.javatpoint.com&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;YvoO&quot;&gt;Reasons for Underfitting:&lt;/p&gt;
  &lt;ul id=&quot;VjtJ&quot;&gt;
    &lt;li id=&quot;HarY&quot;&gt;High bias and low variance&lt;/li&gt;
    &lt;li id=&quot;KXxW&quot;&gt;The size of the training dataset used is not enough.&lt;/li&gt;
    &lt;li id=&quot;5hDa&quot;&gt;The model is too simple.&lt;/li&gt;
    &lt;li id=&quot;w2MO&quot;&gt;Training data is not cleaned and also contains noise in it.&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p id=&quot;jXvq&quot;&gt;Techniques to reduce underfitting: &lt;/p&gt;
  &lt;ul id=&quot;XSfH&quot;&gt;
    &lt;li id=&quot;wC0x&quot;&gt;Increase model complexity&lt;/li&gt;
    &lt;li id=&quot;mqsb&quot;&gt;Remove noise from the data.&lt;/li&gt;
    &lt;li id=&quot;SpRQ&quot;&gt;Increase the size or number of parameters in the model.&lt;/li&gt;
    &lt;li id=&quot;9PoZ&quot;&gt;Increasing the training time, until cost function is minimised.&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p id=&quot;pSM3&quot;&gt;&lt;em&gt;Visual explanation&lt;/em&gt;&lt;/p&gt;
  &lt;figure id=&quot;O2OT&quot; class=&quot;m_column&quot;&gt;
    &lt;img src=&quot;https://media.geeksforgeeks.org/wp-content/uploads/20210323204619/imgonlinecomuaresizeLOjqonkALC.jpg&quot; width=&quot;1100&quot; /&gt;
  &lt;/figure&gt;
  &lt;figure id=&quot;vykj&quot; class=&quot;m_column&quot;&gt;
    &lt;img src=&quot;https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190523171258/overfitting_2.png&quot; width=&quot;1200&quot; /&gt;
    &lt;figcaption&gt;https://www.geeksforgeeks.org/&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;h2 id=&quot;75Su&quot;&gt;Good Fit in a Statistical Model&lt;/h2&gt;
  &lt;p id=&quot;KRFh&quot;&gt;The &amp;quot;Goodness of fit&amp;quot; term is taken from the statistics, and the goal of the machine learning models to achieve the goodness of fit. In statistics modeling, &lt;em&gt;it defines how closely the result or predicted values match the true values of the dataset.&lt;/em&gt;&lt;/p&gt;
  &lt;p id=&quot;R0UX&quot;&gt;The model with a good fit is between the underfitted and overfitted model, and ideally, it makes predictions with 0 errors, but in practice, it is difficult to achieve it.&lt;/p&gt;
  &lt;p id=&quot;QID9&quot;&gt;As when we train our model for a time, the errors in the training data go down, and the same happens with test data. But if we train the model for a long duration, then the performance of the model may decrease due to the overfitting, as the model also learn the noise present in the dataset. The errors in the test dataset start increasing, &lt;em&gt;so the point, just before the raising of errors, is the good point, and we can stop here for achieving a good model.&lt;/em&gt;&lt;/p&gt;
  &lt;h3 id=&quot;N0uz&quot;&gt;References&lt;/h3&gt;
  &lt;p id=&quot;MJGh&quot;&gt;&amp;quot;Overfitting and Underfitting in Machine Learning&amp;quot; &lt;a href=&quot;https://www.javatpoint.com/overfitting-and-underfitting-in-machine-learning#:~:text=Underfitting%20occurs%20when%20our%20machine,enough%20from%20the%20training%20data&quot; target=&quot;_blank&quot;&gt;https://www.javatpoint.com/overfitting-and-underfitting-in-machine-learning#:~:text=Underfitting%20occurs%20when%20our%20machine,enough%20from%20the%20training%20data&lt;/a&gt;.&lt;/p&gt;
  &lt;p id=&quot;RzUS&quot;&gt;&amp;quot;ML | Underfitting and Overfitting&amp;quot; &lt;a href=&quot;https://www.geeksforgeeks.org/underfitting-and-overfitting-in-machine-learning/&quot; target=&quot;_blank&quot;&gt;https://www.geeksforgeeks.org/underfitting-and-overfitting-in-machine-learning/&lt;/a&gt;&lt;/p&gt;
  &lt;p id=&quot;C2mg&quot;&gt;&amp;quot;Overfitting and Underfitting With Machine Learning Algorithms&amp;quot; &lt;a href=&quot;https://machinelearningmastery.com/overfitting-and-underfitting-with-machine-learning-algorithms/&quot; target=&quot;_blank&quot;&gt;https://machinelearningmastery.com/overfitting-and-underfitting-with-machine-learning-algorithms/&lt;/a&gt;&lt;/p&gt;

</content></entry><entry><id>asadbek_universe:CategoricalData</id><link rel="alternate" type="text/html" href="https://teletype.in/@asadbek_universe/CategoricalData?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=asadbek_universe"></link><title>Categorical Data</title><published>2023-01-04T06:23:17.394Z</published><updated>2023-01-04T06:23:17.394Z</updated><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img4.teletype.in/files/f3/45/f3454cf5-b1ce-4e60-b5f4-19c73976989d.png"></media:thumbnail><summary type="html">&lt;img src=&quot;https://www.kdnuggets.com/wp-content/uploads/garg_cat_variables_15.jpg&quot;&gt;The article published in Towards Data Science by Andrew Engel explains clearly about Categorical Variables for Machine Learning Algorithms. I advice you to visit and go over eyes this article</summary><content type="html">
  &lt;blockquote id=&quot;fe5f&quot;&gt;The article published in Towards Data Science by &lt;a href=&quot;https://engelanalytics.medium.com/?source=post_page-----d2768d587ab6--------------------------------&quot; target=&quot;_blank&quot;&gt;Andrew Engel&lt;/a&gt; explains clearly about Categorical Variables for Machine Learning Algorithms. I advice you to visit and go over eyes &lt;a href=&quot;https://towardsdatascience.com/categorical-variables-for-machine-learning-algorithms-d2768d587ab6&quot; target=&quot;_blank&quot;&gt;this article&lt;/a&gt;&lt;/blockquote&gt;
  &lt;p id=&quot;DPHB&quot;&gt;While most machine learning algorithms only work with numeric values, many important real-world features are not numeric but rather categorical. As categorical features, they take on levels or values. These can be represented as various categories such as age, state, or customer type for example. Alternatively, these can be created by binning underlying numeric features, such as identifying individuals by age ranges (e.g., 0–10, 11–18, 19–30, 30–50, etc.). Finally, these can be numeric identifiers where the relationship between the values is not meaningful. ZIP codes are a common example of this. Two ZIP codes close numerically may be farther apart than another ZIP code that is distant numerically.&lt;/p&gt;
  &lt;p id=&quot;ff71&quot;&gt;Since these categorical features cannot be directly used in most machine learning algorithms, the categorical features need to be transformed into numerical features. While numerous techniques exist to transform these features, the most common technique is one-hot encoding.&lt;/p&gt;
  &lt;p id=&quot;62aR&quot;&gt;In one-hot encoding, a categorical variable is converted into a set of binary indicators (one per category in the entire dataset). So in a category that contains the levels clear, partly cloudy, rain, wind, snow, cloudy, fog, seven new variables will be created that contain either &lt;em&gt;1&lt;/em&gt; or &lt;em&gt;0&lt;/em&gt;. Then, for each observation, the variable that matches the category will be set to &lt;em&gt;1 &lt;/em&gt;and all other variables set to &lt;em&gt;0.&lt;/em&gt;&lt;/p&gt;
  &lt;p id=&quot;0LQs&quot;&gt;Let us watch the video tutorial from &lt;a href=&quot;https://www.youtube.com/@codebasics&quot; target=&quot;_blank&quot;&gt;codebasics &lt;/a&gt;channel about Categorical variables, aka Dummies and One Hot Encoding&lt;/p&gt;
  &lt;figure id=&quot;yI4q&quot; class=&quot;m_column&quot;&gt;
    &lt;iframe src=&quot;https://www.youtube.com/embed/9yl6-HEY7_s?autoplay=0&amp;loop=0&amp;mute=0&quot;&gt;&lt;/iframe&gt;
  &lt;/figure&gt;
  &lt;blockquote id=&quot;CUZj&quot;&gt;The code form the tutorial is in github &lt;a href=&quot;https://github.com/codebasics/py/blob/master/ML/5_one_hot_encoding/one_hot_encoding.ipynb&quot; target=&quot;_blank&quot;&gt;https://github.com/codebasics/py/blob/master/ML/5_one_hot_encoding/one_hot_encoding.ipynb&lt;/a&gt;&lt;/blockquote&gt;
  &lt;p id=&quot;yPvc&quot;&gt;Also the article in &lt;a href=&quot;https://www.kdnuggets.com/&quot; target=&quot;_blank&quot;&gt;www.kdnuggets.com&lt;/a&gt; by &lt;strong&gt;Shelvi Garg&lt;/strong&gt; apparently shows how to Deal with Categorical Data for Machine Learning.&lt;/p&gt;
  &lt;p id=&quot;n7Kz&quot;&gt;&lt;strong&gt;Here is the list of the 15 types of encoding the library supports:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul id=&quot;VsxY&quot;&gt;
    &lt;li id=&quot;SrP3&quot;&gt;One-hot Encoding&lt;/li&gt;
    &lt;li id=&quot;bApG&quot;&gt;Label Encoding&lt;/li&gt;
    &lt;li id=&quot;TQE1&quot;&gt;Ordinal Encoding&lt;/li&gt;
    &lt;li id=&quot;j2bJ&quot;&gt;Helmert Encoding&lt;/li&gt;
    &lt;li id=&quot;nvH5&quot;&gt;Binary Encoding&lt;/li&gt;
    &lt;li id=&quot;JJEm&quot;&gt;Frequency Encoding&lt;/li&gt;
    &lt;li id=&quot;EaO2&quot;&gt;Mean Encoding&lt;/li&gt;
    &lt;li id=&quot;exOK&quot;&gt;Weight of Evidence Encoding&lt;/li&gt;
    &lt;li id=&quot;DEhq&quot;&gt;Probability Ratio Encoding&lt;/li&gt;
    &lt;li id=&quot;EkBb&quot;&gt;Hashing Encoding&lt;/li&gt;
    &lt;li id=&quot;O1Xy&quot;&gt;Backward Difference Encoding&lt;/li&gt;
    &lt;li id=&quot;FY5Q&quot;&gt;Leave One Out Encoding&lt;/li&gt;
    &lt;li id=&quot;PrxB&quot;&gt;James-Stein Encoding&lt;/li&gt;
    &lt;li id=&quot;DCES&quot;&gt;M-estimator Encoding&lt;/li&gt;
    &lt;li id=&quot;sngu&quot;&gt;Thermometer Encoder&lt;/li&gt;
  &lt;/ul&gt;
  &lt;figure id=&quot;bEPu&quot; class=&quot;m_column&quot;&gt;
    &lt;img src=&quot;https://www.kdnuggets.com/wp-content/uploads/garg_cat_variables_15.jpg&quot; width=&quot;800&quot; /&gt;
    &lt;figcaption&gt;https://towardsdatascience.com/all-about-categorical-variable-encoding-305f3361fd02&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;xbSK&quot;&gt;Visit &lt;a href=&quot;https://www.kdnuggets.com/2021/05/deal-with-categorical-data-machine-learning.html&quot; target=&quot;_blank&quot;&gt;the webpage&lt;/a&gt; for understanding categorical encoding methods and having a better idea about topic.&lt;/p&gt;

</content></entry></feed>