<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sabbha</title>
    <description>The latest articles on DEV Community by Sabbha (@mondal_sabbha).</description>
    <link>https://dev.to/mondal_sabbha</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F570486%2Fa2903dbf-6524-4535-a1c6-d7b7a97fd65f.png</url>
      <title>DEV Community: Sabbha</title>
      <link>https://dev.to/mondal_sabbha</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mondal_sabbha"/>
    <language>en</language>
    <item>
      <title>Understanding MAE, MSE, and RMSE: Key Metrics in Machine Learning</title>
      <dc:creator>Sabbha</dc:creator>
      <pubDate>Fri, 16 Aug 2024 13:58:55 +0000</pubDate>
      <link>https://dev.to/mondal_sabbha/understanding-mae-mse-and-rmse-key-metrics-in-machine-learning-4la2</link>
      <guid>https://dev.to/mondal_sabbha/understanding-mae-mse-and-rmse-key-metrics-in-machine-learning-4la2</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0h0dh5olp4qpf088ynv4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0h0dh5olp4qpf088ynv4.png" alt="Photo by [Google DeepMind](https://unsplash.com/@googledeepmind) on [Unsplash](https://unsplash.com/)" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the world of machine learning, evaluating the performance of a model is crucial. This evaluation helps us understand how well our model is predicting or classifying data. Among the many metrics available, Mean Absolute Error (MAE), Mean Squared Error (MSE), and Root Mean Squared Error (RMSE) are three of the most commonly used metrics. But why do we use them? What makes them so important?&lt;/p&gt;




&lt;h3&gt;
  
  
  1. Mean Absolute Error (MAE)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What is MAE?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Mean Absolute Error measures the average magnitude of errors in a set of predictions, without considering their direction. It’s the average of the absolute differences between predicted values and actual values.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4p7qntnk0m5jeybk7kpi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4p7qntnk0m5jeybk7kpi.png" alt="MAE" width="800" height="96"&gt;&lt;/a&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwht1715oqlhja0j110n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwht1715oqlhja0j110n.png" alt="desc" width="800" height="157"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why use MAE?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Interpretability:&lt;/strong&gt; MAE provides a clear, straightforward interpretation of the average error. If MAE is 5, on average, the model’s predictions are 5 units off from the actual values.&lt;/li&gt;
&lt;li&gt;**Robustness: **MAE is less sensitive to outliers compared to MSE and RMSE because it doesn’t square the error terms.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;When to use MAE?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;MAE is preferred when you want a direct understanding of the average error without exaggerating the impact of large errors. It’s particularly useful when the dataset has outliers or when the cost of errors is linear.&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Mean Squared Error (MSE)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What is MSE?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Mean Squared Error is the average of the squared differences between the predicted and actual values.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frnbav2x8leoq2er352qa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frnbav2x8leoq2er352qa.png" alt="MSE" width="800" height="96"&gt;&lt;/a&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwht1715oqlhja0j110n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwht1715oqlhja0j110n.png" alt="desc" width="800" height="157"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why use MSE?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Error Amplification:&lt;/strong&gt; By squaring the errors, MSE gives more weight to larger errors, making it a good metric when large errors are particularly undesirable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mathematical Properties:&lt;/strong&gt; MSE is differentiable and often used as a loss function in optimization algorithms like Gradient Descent because its derivative is straightforward to compute.
When to use MSE?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;MSE is often used when large errors are more problematic than small ones, and when you want the metric to penalize large deviations more heavily. It’s also commonly used during model training, as it’s computationally convenient.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Root Mean Squared Error (RMSE)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What is RMSE?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Root Mean Squared Error is the square root of the MSE. It brings the metric back to the original scale of the data, making it easier to interpret than MSE.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4yokjeoc3knfpeucgxvk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4yokjeoc3knfpeucgxvk.png" alt="RMSE" width="800" height="112"&gt;&lt;/a&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwht1715oqlhja0j110n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwht1715oqlhja0j110n.png" alt="desc" width="800" height="157"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why use RMSE?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Interpretability on Scale: RMSE, unlike MSE, is on the same scale as the original data, making it more interpretable.&lt;br&gt;
Sensitive to Large Errors: Like MSE, RMSE also penalizes large errors, but since it’s on the original scale, it can provide a more intuitive measure of the error magnitude.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to use RMSE?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;RMSE is preferred when you want a metric that penalizes large errors but still needs the results to be in the same unit as the original data. It’s widely used in contexts where the distribution of error magnitudes matters and where being on the same scale as the data is crucial.&lt;/p&gt;


&lt;h2&gt;
  
  
  Choosing the Right Metric
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxl3cu98u0hbcli0fxo2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxl3cu98u0hbcli0fxo2.png" alt="Photo by [Jonathan Petersson](https://unsplash.com/@grizzlybear) on [Unsplash](https://unsplash.com/)" width="800" height="532"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MAE&lt;/strong&gt; is more robust to outliers and gives an average error in the same unit as the data, making it easy to interpret.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MSE&lt;/strong&gt; amplifies larger errors, making it useful when larger errors are particularly costly, and it’s often used as a loss function in model training.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RMSE&lt;/strong&gt; combines the benefits of MSE and MAE, offering an error metric that penalizes large errors and remains interpretable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In practice, the choice between MAE, MSE, and RMSE depends on the specific requirements of the problem at hand. If your application requires a simple, interpretable metric, MAE might be the best choice. If you need to penalize larger errors more severely, MSE or RMSE might be more appropriate.&lt;/p&gt;
&lt;h2&gt;
  
  
  Graphical representation
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Setup and Regression Model
&lt;/h3&gt;

&lt;p&gt;Here’s how we can generate a graphical representation of MAE, MSE, and RMSE using a regression model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.linear_model&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;LinearRegression&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.metrics&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;mean_absolute_error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mean_squared_error&lt;/span&gt;

&lt;span class="c1"&gt;# Generate some synthetic data for demonstration
&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;seed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;X&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;X&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;randn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Train a simple linear regression model
&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;LinearRegression&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;y_pred&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Calculate MAE, MSE, and RMSE
&lt;/span&gt;&lt;span class="n"&gt;mae&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mean_absolute_error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_pred&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;mse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mean_squared_error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_pred&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;rmse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mse&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Plotting the regression line with errors
&lt;/span&gt;&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;figure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;figsize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="c1"&gt;# Scatter plot of actual data points
&lt;/span&gt;&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scatter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;blue&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Actual Data&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Regression line
&lt;/span&gt;&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;plot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_pred&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;red&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Regression Line&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Highlighting errors (residuals)
&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;
    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;vlines&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;y_pred&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;gray&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;linestyle&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;dashed&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Adding annotations for MAE, MSE, RMSE
&lt;/span&gt;&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;MAE: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;mae&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fontsize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bbox&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;facecolor&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;white&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;alpha&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;7.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;MSE: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;mse&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fontsize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bbox&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;facecolor&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;white&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;alpha&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;RMSE: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;rmse&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fontsize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bbox&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;facecolor&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;white&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;alpha&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="c1"&gt;# Titles and labels
&lt;/span&gt;&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Linear Regression with MAE, MSE, and RMSE&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;xlabel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;X&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ylabel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;y&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;legend&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fntxlso12nvzu4bm8g49c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fntxlso12nvzu4bm8g49c.png" alt="Linear Regression with MAE, MSE, and RMSE" width="800" height="542"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Explanation of the Plot
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;**Blue Dots: **These represent the actual data points.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Red Line:&lt;/strong&gt; This is the regression line that represents the predicted values from the model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gray Lines:&lt;/strong&gt; These dashed lines represent the residuals or errors for each data point. The length of these lines corresponds to the error magnitude.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MAE, MSE, RMSE:&lt;/strong&gt; Annotated in the plot, these values are displayed to help visualize how the model’s performance is evaluated.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Interpretation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MAE&lt;/strong&gt;: Gives an average error in the same unit as the data, showing the average distance of the data points from the regression line.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MSE&lt;/strong&gt;: Squares the errors, emphasizing larger errors more and is often used during the training of regression models.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RMSE&lt;/strong&gt;: Provides a metric on the same scale as the original data, making it more interpretable than MSE while still penalizing larger errors.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Training a machine learning model
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj7zs3cb5w1pcju187dmz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj7zs3cb5w1pcju187dmz.png" alt="Photo by [JESHOOTS.COM](https://unsplash.com/@jeshoots) on [Unsplash](https://unsplash.com/)" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When training a machine learning model, especially in regression tasks, choosing the right error metric is crucial because it influences how the model learns and how its performance is evaluated. Let’s break down the significance of MAE, MSE, and RMSE in model training:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. MAE (Mean Absolute Error)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Definition&lt;/strong&gt;: MAE is the average of the absolute differences between the predicted and actual values.&lt;/p&gt;

&lt;h4&gt;
  
  
  Significance in Model Training:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Robustness to Outliers&lt;/strong&gt;: MAE is less sensitive to outliers compared to MSE and RMSE because it treats all errors equally without squaring them. This means that during training, the model will aim to minimize the average error without disproportionately focusing on larger errors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Linear Penalty&lt;/strong&gt;: The linear nature of MAE means that the impact of each error on the model’s learning process is directly proportional to the magnitude of that error.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interpretability&lt;/strong&gt;: MAE is in the same units as the original data, making it easier to interpret. If the MAE is 5, it means that on average, the model’s predictions are off by 5 units.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. MSE (Mean Squared Error)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Definition&lt;/strong&gt;: MSE is the average of the squared differences between the predicted and actual values.&lt;/p&gt;

&lt;h4&gt;
  
  
  Significance in Model Training:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sensitivity to Outliers&lt;/strong&gt;: MSE is sensitive to outliers because it squares the error, making larger errors much more significant in the calculation. This causes the model to prioritize reducing large errors during training.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Punishing Large Errors&lt;/strong&gt;: The squaring effect means that the model will penalize larger errors more severely, which can lead to a better fit for most data points but might overfit to outliers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smooth Gradient&lt;/strong&gt;: MSE is widely used in optimization algorithms like gradient descent because it provides a smooth gradient, making it easier for the model to converge during training.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Model’s Focus on Large Errors&lt;/strong&gt;: Since large errors have a bigger impact, the model might focus on reducing these at the cost of slightly increasing smaller errors, which can be beneficial if large errors are particularly undesirable in the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. RMSE (Root Mean Squared Error)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Definition&lt;/strong&gt;: RMSE is the square root of the average of the squared differences between the predicted and actual values.&lt;/p&gt;

&lt;h4&gt;
  
  
  Significance in Model Training:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Balance between MAE and MSE&lt;/strong&gt;: RMSE retains the sensitivity to outliers like MSE but brings the error metric back to the original scale of the data, making it more interpretable than MSE.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Penalizes Large Errors&lt;/strong&gt;: Similar to MSE, RMSE also penalizes larger errors more due to the squaring process, but because it takes the square root, it doesn’t exaggerate them as much as MSE does.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interpretable Units&lt;/strong&gt;: Since RMSE is on the same scale as the original data, it’s easier to understand in the context of the problem. For instance, an RMSE of 5 means that on average, the model’s prediction errors are about 5 units away from the actual values.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimization in Complex Models&lt;/strong&gt;: RMSE is often used in models where the distribution of errors is important, such as in complex regression models or neural networks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Visual Example to Show Significance in Model Training:
&lt;/h3&gt;

&lt;p&gt;Let’s consider a graphical representation that shows how these metrics affect the model’s training process.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MAE Focuses on Reducing Average Error&lt;/strong&gt;: Imagine the model adjusting the regression line to minimize the average height of the gray dashed lines (errors) equally for all points.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MSE Prioritizes Reducing Large Errors&lt;/strong&gt;: The model might adjust the line more drastically to reduce the longer dashed lines (larger errors), even if it means increasing some smaller ones.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RMSE Balances Both&lt;/strong&gt;: The model will make adjustments that reduce large errors but will not overemphasize them to the extent of distorting the overall fit.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.linear_model&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;LinearRegression&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.metrics&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;mean_absolute_error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mean_squared_error&lt;/span&gt;

&lt;span class="c1"&gt;# Generate synthetic data with an outlier
&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;seed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;X&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;X&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;randn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;98&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;  &lt;span class="c1"&gt;# Adding an outlier
&lt;/span&gt;
&lt;span class="c1"&gt;# Train a simple linear regression model
&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;LinearRegression&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;y_pred&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Calculate MAE, MSE, and RMSE
&lt;/span&gt;&lt;span class="n"&gt;mae&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mean_absolute_error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_pred&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;mse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mean_squared_error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_pred&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;rmse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mse&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Plotting the regression line with errors
&lt;/span&gt;&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;figure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;figsize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="c1"&gt;# Scatter plot of actual data points
&lt;/span&gt;&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scatter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;blue&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Actual Data&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Regression line
&lt;/span&gt;&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;plot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_pred&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;red&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Regression Line&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Highlighting errors (residuals)
&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;
    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;vlines&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;y_pred&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;gray&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;linestyle&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;dashed&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Annotating one of the residual lines
&lt;/span&gt;&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;y_pred&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Error (Residual)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;gray&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Adding annotations for MAE, MSE, RMSE
&lt;/span&gt;&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;MAE: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;mae&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fontsize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bbox&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;facecolor&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;white&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;alpha&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;MSE: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;mse&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fontsize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bbox&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;facecolor&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;white&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;alpha&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;RMSE: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;rmse&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fontsize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bbox&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;facecolor&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;white&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;alpha&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="c1"&gt;# Titles and labels
&lt;/span&gt;&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Linear Regression with MAE, MSE, and RMSE - Impact on Model Training&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;xlabel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;X&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ylabel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;y&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;legend&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8curfks36zryhdypf3eq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8curfks36zryhdypf3eq.png" alt="Linear Regression with MAE, MSE, and RMSE - Impact on Model Training" width="800" height="534"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Explanation:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Outlier Impact&lt;/strong&gt;: Notice how the model tries to adjust for the outlier in the upper region, which affects MSE and RMSE more significantly.&lt;/p&gt;

&lt;h4&gt;
  
  
  Model Training Implications:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;With MAE&lt;/strong&gt;: The model may place less emphasis on the outlier, leading to a fit that is more balanced but less sensitive to extreme deviations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;With MSE and RMSE&lt;/strong&gt;: The model might adjust more aggressively to minimize the impact of the outlier, which can lead to a more distorted fit if outliers are rare.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Choosing the right approach for training a model depends on the specific problem you’re trying to solve, the nature of your data, and the goals of your model. Here’s a guide to help you decide which metric (MAE, MSE, RMSE) to focus on, along with considerations for training your model:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Nature of the Data
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Presence of Outliers:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MAE&lt;/strong&gt;: If your data contains outliers, and you don’t want these outliers to disproportionately affect your model, MAE is a good choice. It treats all errors equally, so a few large errors won’t dominate the metric.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MSE/RMSE&lt;/strong&gt;: If outliers are expected and meaningful (e.g., extreme but valid cases), and you want your model to account for them strongly, MSE or RMSE might be more appropriate.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Homogeneous Data:
&lt;/h3&gt;

&lt;p&gt;If your data is relatively homogeneous, without significant outliers, MSE or RMSE can help capture the overall performance, focusing more on the general fit of the model.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Goal of the Model
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Interpretability:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MAE&lt;/strong&gt;: Offers easier interpretation since it’s in the same units as the target variable. If interpretability in the original units is essential, and you want to understand the average error in simple terms, MAE is preferable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RMSE&lt;/strong&gt;: Also interpretable in the same units but with a focus on penalizing larger errors more.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Focus on Larger Errors:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MSE/RMSE&lt;/strong&gt;: If you care more about larger errors because they are particularly costly or risky in your application (e.g., predicting medical doses, financial forecasts), MSE or RMSE should be your focus. These metrics penalize larger errors more, which can guide the model to prioritize reducing significant deviations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MAE&lt;/strong&gt;: If your application treats all errors equally and you don’t want the model to be overly concerned with large deviations, MAE is a better choice.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Model Type and Complexity
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Simple Linear Models:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MAE&lt;/strong&gt;: Works well with simple linear models where the goal is to minimize the average deviation without worrying too much about outliers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MSE/RMSE&lt;/strong&gt;: Can also be used, especially if the model is expected to account for all data points, including extreme cases.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Complex Models (e.g., Neural Networks, Ensemble Methods):
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MSE/RMSE&lt;/strong&gt;: These are commonly used in more complex models because they provide a smoother gradient, which is essential for optimization techniques like gradient descent. The penalization of larger errors can also help in fine-tuning complex models.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. Optimization and Convergence
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Gradient Descent and Optimization:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MSE/RMSE&lt;/strong&gt;: Often preferred in optimization algorithms because they provide a smooth and continuous error surface, which is essential for methods like gradient descent to converge effectively.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MAE&lt;/strong&gt;: Can be less smooth, which might make optimization slightly more challenging, especially in large-scale models. However, modern optimization techniques can handle this in many cases.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. Contextual Considerations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Application-Specific Requirements:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MAE&lt;/strong&gt;: Ideal for applications where you need to avoid the influence of outliers or when the cost of an error is linear, such as estimating delivery times or predicting scores.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MSE/RMSE&lt;/strong&gt;: Best for situations where large errors are particularly undesirable and where the application demands a higher penalty for these errors, such as in high-stakes financial predictions, safety-critical systems, or when optimizing models in competitive environments.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusion: Which Approach to Take
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;If Outliers are Not a Major Concern&lt;/strong&gt;: Use MSE or RMSE. They help the model pay attention to larger errors, which can be crucial in many applications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;If You Want a Balanced Approach&lt;/strong&gt;: RMSE is often a good compromise, as it gives a measure in the same units as the target variable while still penalizing larger errors more than smaller ones.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;If You Need Robustness to Outliers&lt;/strong&gt;: Use MAE. It ensures that outliers don’t disproportionately influence the model, making it suitable for situations where you want a more balanced model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;For Interpretability in Original Units&lt;/strong&gt;: MAE or RMSE are easier to interpret since they are in the same units as your target variable. This can be especially important in domains where you need to explain the results to non-technical stakeholders.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In practice, you might start with one metric based on these considerations and then experiment to see how your model performs with each. It’s also common to monitor multiple metrics during training to get a well-rounded view of your model’s performance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@mondalsabbha/understanding-mae-mse-and-rmse-key-metrics-in-machine-learning-eeeff8bd1fac" rel="noopener noreferrer"&gt;Medium Article - Understanding MAE, MSE, and RMSE: Key Metrics in Machine Learning&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@mondalsabbha" rel="noopener noreferrer"&gt;@mondalsabbha&lt;/a&gt;&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>python</category>
      <category>regressionmodel</category>
    </item>
    <item>
      <title>Introduction to Linked Lists in Python: A Comprehensive Guide 🔗</title>
      <dc:creator>Sabbha</dc:creator>
      <pubDate>Wed, 14 Aug 2024 05:10:46 +0000</pubDate>
      <link>https://dev.to/mondal_sabbha/introduction-to-linked-lists-in-python-a-comprehensive-guide-366g</link>
      <guid>https://dev.to/mondal_sabbha/introduction-to-linked-lists-in-python-a-comprehensive-guide-366g</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fljotlbaor8h6fczv5xxx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fljotlbaor8h6fczv5xxx.png" alt="Photo by [Becca Tapert](https://unsplash.com/@beccatapert) on [Unsplash](https://unsplash.com)" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  What is a Linked List?
&lt;/h2&gt;

&lt;p&gt;A linked list is a fundamental data structure that consists of a sequence of elements, where each element points to the next one. Unlike arrays, linked lists do not require contiguous memory locations, making them dynamic and flexible in nature. They are widely used in scenarios where frequent insertions and deletions are required.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs9vzv8zgou7qvc7iibos.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs9vzv8zgou7qvc7iibos.png" alt="Chains Linked" width="512" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article, we'll explore the concept of linked lists, understand their structure, and implement a simple linked list in Python. By the end, you'll have a solid understanding of how linked lists work and how to use them in your projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Structure of a Linked List
&lt;/h2&gt;

&lt;p&gt;A linked list is composed of nodes. Each node contains:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Data: The actual value or information the node holds.&lt;/li&gt;
&lt;li&gt;Next: A reference (or pointer) to the next node in the sequence.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first node of a linked list is called the head. The last node has a next reference that points to None, indicating the end of the list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Data|Next] -&amp;gt; [Data|Next] -&amp;gt; [Data|Next] -&amp;gt; None
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fli6vfedknkqyw4gp12dh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fli6vfedknkqyw4gp12dh.png" alt="Linked List" width="512" height="512"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Use Linked Lists?
&lt;/h2&gt;

&lt;p&gt;Linked lists offer several advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dynamic Size: They can grow or shrink dynamically, without requiring memory reallocation.&lt;/li&gt;
&lt;li&gt;Efficient Insertions/Deletions: Adding or removing elements is more efficient than in arrays, especially when dealing with large datasets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;However, linked lists also come with some drawbacks:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sequential Access: Accessing an element requires traversing the list from the head, making it slower than arrays for random access.&lt;/li&gt;
&lt;li&gt;Memory Overhead: Each element requires extra memory for storing the reference to the next node.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwd2alrsmf5k11shvi53q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwd2alrsmf5k11shvi53q.png" alt="Chain of beads" width="512" height="512"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Here's a basic implementation of a singly linked list in Python, along with an explanation of how it works:&lt;/p&gt;

&lt;h2&gt;
  
  
  Linked List Implementation
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Creating the Node Class
&lt;/h3&gt;

&lt;p&gt;The first step is to create a Node class. Each Node object will store the data and a reference to the next node.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Node:
    def __init__(self, data=None):
        self.data = data
        self.next = None
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, data holds the value of the node, and next is a pointer to the next node in the list.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Creating the LinkedList Class
&lt;/h3&gt;

&lt;p&gt;Next, we'll create a LinkedList class to manage the nodes. This class will include methods to add nodes, display the list, and perform various operations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class LinkedList:
    def __init__(self):
        self.head = None
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The head attribute represents the starting point of the linked list.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Adding Nodes to the Linked List
&lt;/h3&gt;

&lt;p&gt;We can create a method called append to add nodes at the end of the list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def append(self, data):
    new_node = Node(data)
    if not self.head:
        self.head = new_node
        return
    last = self.head
    while last.next:
        last = last.next
    last.next = new_node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method creates a new node and adds it to the end of the list. If the list is empty, the new node becomes the head.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Displaying the Linked List
&lt;/h3&gt;

&lt;p&gt;To visualize the linked list, we can create a display method that prints the elements in sequence.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def display(self):
    current = self.head
    while current:
        print(current.data, end=" -&amp;gt; ")
        current = current.next
    print("None")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method traverses the list from the head to the last node and prints the data of each node.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Finding a Node in the Linked List
&lt;/h3&gt;

&lt;p&gt;We can create a find method to search for a specific value in the list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def find(self, key):
    current = self.head
    while current:
        if current.data == key:
            return True
        current = current.next
    return False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method traverses the list and returns True if the value is found, otherwise it returns False.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6: Deleting a Node from the Linked List
&lt;/h3&gt;

&lt;p&gt;We can create a delete method to remove a node with a specific value from the list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def delete(self, key):
    current = self.head
    prev = None

    # If the node to be deleted is the head
    if current and current.data == key:
        self.head = current.next
        current = None
        return

    # Search for the node to be deleted
    while current and current.data != key:
        prev = current
        current = current.next

    # If the node was not found
    if not current:
        return

    # Unlink the node from the linked list
    prev.next = current.next
    current = None
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method searches for the node with the specified value and removes it from the list. If the node is not found, no action is taken.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 7: Inserting Nodes at Specific Positions
&lt;/h3&gt;

&lt;p&gt;Sometimes, you may need to insert a node at a specific position. We can implement an insert method for this purpose.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def insert(self, position, data):
    new_node = Node(data)
    if position == 0:
        new_node.next = self.head
        self.head = new_node
        return

    current = self.head
    prev = None
    current_position = 0

    while current and current_position &amp;lt; position:
        prev = current
        current = current.next
        current_position += 1

    new_node.next = current
    if prev:
        prev.next = new_node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method allows you to insert a node at any specified position in the list. If the position is 0, the new node becomes the head.&lt;/p&gt;




&lt;h2&gt;
  
  
  Example Usage
&lt;/h2&gt;

&lt;p&gt;Let's see how these methods work together in a simple example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Creating a linked list and appending elements
linked_list = LinkedList()
linked_list.append(1)
linked_list.append(3)
linked_list.append(4)

# Displaying the original list
print("Original List:")
linked_list.display()  # Output: 1 -&amp;gt; 3 -&amp;gt; 4 -&amp;gt; None

# Inserting a node at position 1
linked_list.insert(1, 2)
print("After Inserting 2 at position 1:")
linked_list.display()  # Output: 1 -&amp;gt; 2 -&amp;gt; 3 -&amp;gt; 4 -&amp;gt; None

# Inserting a node at the head
linked_list.insert(0, 0)
print("After Inserting 0 at position 0 (head):")
linked_list.display()  # Output: 0 -&amp;gt; 1 -&amp;gt; 2 -&amp;gt; 3 -&amp;gt; 4 -&amp;gt; None

# Inserting a node at the end
linked_list.insert(5, 5)
print("After Inserting 5 at the end:")
linked_list.display()  # Output: 0 -&amp;gt; 1 -&amp;gt; 2 -&amp;gt; 3 -&amp;gt; 4 -&amp;gt; 5 -&amp;gt; None

# Finding a node in the list
print("Finding 3 in the list:")
print(linked_list.find(3))  # Output: True

print("Finding 6 in the list:")
print(linked_list.find(6))  # Output: False

# Deleting a node from the list
linked_list.delete(3)
print("After Deleting 3:")
linked_list.display()  # Output: 0 -&amp;gt; 1 -&amp;gt; 2 -&amp;gt; 4 -&amp;gt; 5 -&amp;gt; None

# Deleting the head node
linked_list.delete(0)
print("After Deleting the head (0):")
linked_list.display()  # Output: 1 -&amp;gt; 2 -&amp;gt; 4 -&amp;gt; 5 -&amp;gt; None
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Linked lists are a powerful and flexible data structure, providing efficient operations for insertion, deletion, and searching. While they may not be as fast as arrays for random access, their dynamic nature makes them ideal for scenarios where the size of the data structure is unknown or changes frequently.&lt;br&gt;
In this article, we covered the basics of linked lists, including their structure, benefits, and how to implement them in Python. We also explored essential operations like appending nodes, displaying the list, finding nodes, and deleting nodes.&lt;br&gt;
By practicing with linked lists, you'll gain a deeper understanding of how data structures work, which is essential for writing efficient algorithms and solving complex problems. Whether you're preparing for coding interviews or just looking to improve your programming skills, mastering linked lists is a key step in becoming a proficient developer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Happy coding!
&lt;/h3&gt;

</description>
      <category>linkedlist</category>
      <category>dsa</category>
      <category>datastructures</category>
      <category>python</category>
    </item>
    <item>
      <title>MOBILE FRAMEWORKS: Flutter vs .NET MAUI vs Kotlin Multiplatform Mobile (KMM) vs React Native</title>
      <dc:creator>Sabbha</dc:creator>
      <pubDate>Fri, 02 Aug 2024 10:02:22 +0000</pubDate>
      <link>https://dev.to/mondal_sabbha/mobile-frameworks-flutter-vs-net-maui-vs-kotlin-multiplatform-mobile-kmm-vs-react-native-36pc</link>
      <guid>https://dev.to/mondal_sabbha/mobile-frameworks-flutter-vs-net-maui-vs-kotlin-multiplatform-mobile-kmm-vs-react-native-36pc</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F88yxgbcopd3lvg4gpfpr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F88yxgbcopd3lvg4gpfpr.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When comparing .NET MAUI, Kotlin Multiplatform Mobile (KMM), Flutter, and React Native, several factors need to be considered, including performance, speed, app size, development ease, community support, and platform-specific capabilities. Here’s a breakdown:&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance and Speed
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;.NET MAUI:&lt;/strong&gt; As a part of the .NET ecosystem, it provides near-native performance by compiling to native code. The performance is generally good, but the ecosystem and tooling are still evolving.&lt;br&gt;
&lt;strong&gt;Kotlin Multiplatform Mobile (KMM):&lt;/strong&gt; Offers near-native performance for Android apps since it uses Kotlin, which is the preferred language for Android development. The iOS performance is also good, leveraging Kotlin Native.&lt;br&gt;
&lt;strong&gt;Flutter:&lt;/strong&gt; Uses Dart and compiles to native ARM code for both iOS and Android. Known for high performance and smooth animations due to its custom rendering engine.&lt;br&gt;
&lt;strong&gt;React Native:&lt;/strong&gt; Utilizes a JavaScript bridge to communicate with native modules, which can introduce some performance overhead. However, it provides good performance for most use cases, though it might lag behind Flutter in graphics-intensive applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  App Size
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;.NET MAUI:&lt;/strong&gt; Apps tend to be larger due to the inclusion of the .NET runtime, but ongoing improvements are reducing the overhead.&lt;br&gt;
&lt;strong&gt;KMM:&lt;/strong&gt; The app size is generally optimized as it uses native components and compiles to native binaries, but it can vary depending on the shared code and platform-specific implementations.&lt;br&gt;
&lt;strong&gt;Flutter:&lt;/strong&gt; Flutter apps are usually larger due to the inclusion of the Flutter engine and framework libraries. However, optimizations are regularly being made.&lt;br&gt;
&lt;strong&gt;React Native:&lt;/strong&gt; React Native apps can be smaller than Flutter apps since they rely on native components and a JavaScript runtime, but additional libraries can increase the size.&lt;/p&gt;

&lt;h2&gt;
  
  
  Development Ease
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;.NET MAUI:&lt;/strong&gt; Integrates well with Visual Studio, providing a rich development environment. Suitable for developers familiar with the .NET ecosystem.&lt;br&gt;
&lt;strong&gt;KMM:&lt;/strong&gt; Developers can write business logic once and share it across platforms. However, the UI code still needs to be written separately for each platform, which can be challenging.&lt;br&gt;
&lt;strong&gt;Flutter:&lt;/strong&gt; Offers a single codebase for both iOS and Android, with a hot reload feature that speeds up development. The rich set of widgets and comprehensive documentation make it developer-friendly.&lt;br&gt;
&lt;strong&gt;React Native:&lt;/strong&gt; Also provides a single codebase for iOS and Android with hot reload capabilities. The learning curve can be lower for developers familiar with JavaScript and React.&lt;/p&gt;

&lt;h2&gt;
  
  
  Community and Ecosystem
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;.NET MAUI:&lt;/strong&gt; Growing community with strong support from Microsoft. The ecosystem is expanding but is not as mature as some of the other frameworks.&lt;br&gt;
&lt;strong&gt;KMM: ** Backed by JetBrains, it has a growing community, especially among Kotlin developers. The ecosystem is evolving, with more libraries and tools becoming available.&lt;br&gt;
**Flutter:&lt;/strong&gt; Very active community with strong support from Google. Extensive ecosystem with a vast number of packages and plugins available.&lt;br&gt;
&lt;strong&gt;React Native:&lt;/strong&gt; One of the largest communities among cross-platform frameworks, backed by Facebook. A mature ecosystem with a wide range of libraries and third-party plugins.&lt;/p&gt;

&lt;h2&gt;
  
  
  Platform-Specific Capabilities
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;.NET MAUI:&lt;/strong&gt; Good integration with platform-specific APIs through .NET bindings. Allows for a high degree of code reuse while still enabling platform-specific functionality.&lt;br&gt;
&lt;strong&gt;KMM:&lt;/strong&gt; Provides a high degree of code sharing while allowing for platform-specific code where necessary. Strong support for Android, with growing support for iOS.&lt;br&gt;
&lt;strong&gt;Flutter:&lt;/strong&gt; Offers a high level of platform-specific customization through platform channels. The custom rendering engine allows for consistent UI across platforms.&lt;br&gt;
&lt;strong&gt;React Native:&lt;/strong&gt; Access to native modules and third-party libraries provides extensive platform-specific capabilities. JavaScript bridge allows for easy integration with existing native code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fno0xp3uatk1k217phbo4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fno0xp3uatk1k217phbo4.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Notes:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Ranking is a general guideline and can vary depending on specific project needs.&lt;/li&gt;
&lt;li&gt;Development ease is subjective and depends on developer experience.&lt;/li&gt;
&lt;li&gt;.NET MAUI is under active development, so performance and app size may improve in the future.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Additional Considerations:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Learning Curve: Consider the existing skills of your development team.&lt;/li&gt;
&lt;li&gt;Project Requirements: Choose a framework that best suits your app’s performance and platform-specific needs.&lt;/li&gt;
&lt;li&gt;Development Speed: If fast turnaround is crucial, consider the framework with the quickest development cycle.&lt;/li&gt;
&lt;li&gt;Long-Term Support: Choose a framework with a healthy and active community for ongoing support.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  DIVING DEEP
&lt;/h2&gt;

&lt;p&gt;Let's dive deeper into each of these frameworks: .NET MAUI, Kotlin Multiplatform Mobile (KMM), Flutter, and React Native. We'll explore their performance, app size, development ease, community and ecosystem, platform-specific capabilities, and more in detail.&lt;/p&gt;




&lt;h2&gt;
  
  
  .NET MAUI (Multi-platform App UI)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Performance and Speed
&lt;/h3&gt;

&lt;p&gt;.NET MAUI is the evolution of Xamarin.Forms and part of the larger .NET ecosystem. It aims to provide a single framework for building applications across multiple platforms, including Android, iOS, macOS, and Windows.&lt;br&gt;
&lt;strong&gt;Performance:&lt;/strong&gt;.NET MAUI compiles to native code, which typically results in near-native performance. The framework leverages the Mono runtime on Android and the .NET runtime on iOS, which are highly optimized for performance. Moreover, the use of Ahead-of-Time (AOT) compilation and Just-in-Time (JIT) compilation helps in achieving better performance. Since .NET MAUI uses platform-native UI components, it ensures that the apps are as performant as their native counterparts.&lt;br&gt;
&lt;strong&gt;Speed:&lt;/strong&gt; The speed of .NET MAUI apps can be attributed to several factors, including the use of native UI components, AOT compilation, and the efficiency of the .NET runtime. Additionally, the framework's integration with Visual Studio and other .NET tools can enhance development speed by providing a rich and efficient development environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  App Size
&lt;/h3&gt;

&lt;p&gt;Apps developed with .NET MAUI tend to be larger due to the inclusion of the .NET runtime and libraries. This overhead is a trade-off for the cross-platform capabilities and the rich set of features provided by the .NET ecosystem. However, Microsoft is actively working on optimizing the app size by trimming unnecessary libraries and components during the build process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Development Ease
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Integrated Development Environment (IDE):&lt;/strong&gt; .NET MAUI is tightly integrated with Visual Studio, which is one of the most robust IDEs available. Visual Studio provides a comprehensive set of tools for coding, debugging, and testing. The integration allows for features like IntelliSense, code refactoring, and visual designers for building UIs, which significantly ease the development process.&lt;br&gt;
&lt;strong&gt;Learning Curve:&lt;/strong&gt; For developers already familiar with the .NET ecosystem and languages like C#, the learning curve for .NET MAUI is relatively shallow. The framework follows similar patterns and paradigms as other .NET technologies, making it easier for .NET developers to get up to speed.&lt;br&gt;
&lt;strong&gt;Cross-Platform Capabilities:&lt;/strong&gt; .NET MAUI offers a single project structure for building applications across multiple platforms. This structure simplifies the development process by allowing developers to write code once and run it on multiple platforms. Additionally, .NET MAUI provides platform-specific APIs and controls, enabling developers to implement platform-specific features and UI elements when needed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Community and Ecosystem
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Community Support:&lt;/strong&gt; The .NET community is large and active, with numerous resources, forums, and user groups available for support. Microsoft also provides extensive documentation, tutorials, and sample projects to help developers learn and use .NET MAUI effectively.&lt;br&gt;
&lt;strong&gt;Ecosystem:&lt;/strong&gt; .NET MAUI is part of the broader .NET ecosystem, which includes a wide range of libraries, tools, and frameworks. This integration allows developers to leverage existing .NET libraries and tools, such as Entity Framework for data access, ASP.NET for web development, and Azure for cloud services. The extensive ecosystem provides a wealth of resources and tools to aid in the development process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Platform-Specific Capabilities
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Native UI Components:&lt;/strong&gt; .NET MAUI uses platform-native UI components, ensuring that the user interface looks and feels native on each platform. This approach not only enhances performance but also provides a consistent user experience.&lt;br&gt;
&lt;strong&gt;Platform-Specific APIs:&lt;/strong&gt; .NET MAUI provides access to platform-specific APIs through dependency services and platform-specific code. This capability allows developers to implement features that are unique to a specific platform while still maintaining a shared codebase for common functionality.&lt;br&gt;
&lt;strong&gt;Extensibility:&lt;/strong&gt; .NET MAUI is highly extensible, allowing developers to create custom controls, behaviors, and effects. The framework also supports third-party libraries and components, which can be easily integrated into .NET MAUI projects.&lt;/p&gt;




&lt;h2&gt;
  
  
  Kotlin Multiplatform Mobile (KMM)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Performance and Speed
&lt;/h3&gt;

&lt;p&gt;Kotlin Multiplatform Mobile (KMM) is a part of JetBrains' Kotlin Multiplatform project, which aims to share code between multiple platforms. KMM specifically focuses on sharing code between Android and iOS.&lt;br&gt;
&lt;strong&gt;Performance:&lt;/strong&gt; KMM offers near-native performance by using Kotlin for both Android and iOS development. On Android, KMM leverages the Kotlin JVM, which provides excellent performance due to its optimized runtime. On iOS, KMM uses Kotlin Native, which compiles to native binaries, ensuring high performance.&lt;br&gt;
&lt;strong&gt;Speed:&lt;/strong&gt; The speed of KMM applications is comparable to native apps since it uses platform-native components and APIs. The shared business logic is compiled to native code, which eliminates the performance overhead associated with interpreted languages.&lt;/p&gt;

&lt;h3&gt;
  
  
  App Size
&lt;/h3&gt;

&lt;p&gt;The app size in KMM is generally optimized, as it uses native components and compiles to native binaries. However, the app size can vary depending on the amount of shared code and the specific implementations for each platform. JetBrains is continuously working on optimizing the output size to ensure that KMM apps remain lightweight.&lt;/p&gt;

&lt;h3&gt;
  
  
  Development Ease
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Shared Codebase:&lt;/strong&gt; KMM allows developers to write business logic once and share it across both Android and iOS. This shared codebase significantly reduces the amount of duplicated code and simplifies maintenance. However, the UI code still needs to be written separately for each platform, which can add complexity.&lt;br&gt;
&lt;strong&gt;IDE Support:&lt;/strong&gt; KMM is well-supported in IntelliJ IDEA and Android Studio, providing a familiar development environment for Kotlin developers. These IDEs offer powerful tools for coding, debugging, and testing, along with seamless integration with KMM.&lt;br&gt;
&lt;strong&gt;Learning Curve:&lt;/strong&gt; For developers familiar with Kotlin, the learning curve for KMM is relatively low. The framework follows the same syntax and conventions as Kotlin, making it easier for Kotlin developers to adopt KMM. However, developers need to be comfortable with both Android and iOS development paradigms.&lt;/p&gt;

&lt;h3&gt;
  
  
  Community and Ecosystem
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Community Support:&lt;/strong&gt; The Kotlin community is active and growing, with a strong presence in the Android development space. JetBrains provides extensive documentation, tutorials, and sample projects to help developers learn and use KMM. The community also contributes to various open-source libraries and tools that support KMM development.&lt;br&gt;
&lt;strong&gt;Ecosystem:&lt;/strong&gt; KMM is part of the larger Kotlin ecosystem, which includes a wide range of libraries and tools. The integration with existing Kotlin libraries, such as Ktor for networking and Kotlinx.serialization for data serialization, allows developers to reuse familiar tools and libraries in their KMM projects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Platform-Specific Capabilities
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Native Integration:&lt;/strong&gt; KMM allows for deep integration with platform-specific APIs and components. Developers can write platform-specific code when necessary, enabling them to take full advantage of the unique capabilities of each platform.&lt;br&gt;
&lt;strong&gt;Code Sharing:&lt;/strong&gt; The primary strength of KMM lies in its ability to share business logic across platforms. This shared code can include data models, network requests, and other non-UI logic, which reduces duplication and simplifies maintenance.&lt;br&gt;
&lt;strong&gt;Interoperability:&lt;/strong&gt; KMM provides interoperability with existing codebases, allowing developers to incrementally adopt KMM in their projects. This capability is particularly useful for large projects where a full rewrite is not feasible.&lt;/p&gt;




&lt;h2&gt;
  
  
  Flutter
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Performance and Speed
&lt;/h3&gt;

&lt;p&gt;Flutter, developed by Google, is an open-source UI toolkit for building natively compiled applications for mobile, web, and desktop from a single codebase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance:&lt;/strong&gt; Flutter uses the Dart language and compiles to native ARM code for both iOS and Android. The framework includes a high-performance rendering engine called Skia, which enables smooth and fast UI rendering. Flutter's architecture minimizes the bridge between the UI and native code, reducing performance overhead and ensuring high performance.&lt;br&gt;
&lt;strong&gt;Speed:&lt;/strong&gt; Flutter applications are known for their speed, particularly in rendering complex and animated UIs. The framework's hot reload feature allows developers to see changes in real-time, significantly speeding up the development process.&lt;/p&gt;

&lt;h3&gt;
  
  
  App Size
&lt;/h3&gt;

&lt;p&gt;Flutter apps are generally larger due to the inclusion of the Flutter engine and framework libraries. The initial app size can be more significant than native apps, but ongoing optimizations are being made to reduce the overhead. Additionally, the app size can increase depending on the number of third-party packages and assets used.&lt;/p&gt;

&lt;h3&gt;
  
  
  Development Ease
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Single Codebase:&lt;/strong&gt; Flutter offers a single codebase for both iOS and Android, simplifying the development process and reducing the amount of duplicated code. This single codebase approach also makes it easier to maintain and update applications.&lt;br&gt;
&lt;strong&gt;Hot Reload:&lt;/strong&gt; One of Flutter's standout features is hot reload, which allows developers to see changes in real-time without restarting the app. This feature significantly speeds up the development process and makes it easier to iterate on designs and functionality.&lt;br&gt;
&lt;strong&gt;Comprehensive Widgets:&lt;/strong&gt; Flutter provides a rich set of customizable widgets for building UIs. These widgets are designed to look and feel native on both iOS and Android, ensuring a consistent user experience. The comprehensive documentation and extensive set of examples make it easy for developers to get started with Flutter.&lt;/p&gt;

&lt;h3&gt;
  
  
  Community and Ecosystem
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Community Support:&lt;/strong&gt; Flutter has a very active and rapidly growing community. Google provides extensive documentation, tutorials, and sample projects to help developers learn and use Flutter. The community also contributes to a wide range of open-source packages and plugins, which can be easily integrated into Flutter projects.&lt;br&gt;
&lt;strong&gt;Ecosystem:&lt;/strong&gt; Flutter has an extensive ecosystem with a vast number of packages and plugins available through the Dart package manager, pub.dev. These packages cover a wide range of functionalities, from UI components to state management and backend integration. The strong ecosystem and community support make it easy to find solutions and resources for common development tasks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Platform-Specific Capabilities
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Custom Rendering Engine:&lt;/strong&gt; Flutter uses its custom rendering engine, Skia, which enables consistent UI rendering across platforms. This engine allows developers to create highly customized and performant UIs without relying on platform-native components.&lt;br&gt;
&lt;strong&gt;Platform Channels:&lt;/strong&gt; Flutter provides platform channels for communicating with native code, enabling developers to access platform-specific APIs and functionality. This capability allows for deep integration with platform-specific features while maintaining a shared codebase for common functionality.&lt;br&gt;
&lt;strong&gt;Extensibility:&lt;/strong&gt; Flutter is highly extensible, allowing developers to create custom widgets and plugins. The framework also supports third-party libraries and components, which can be easily integrated into Flutter projects.&lt;/p&gt;




&lt;h2&gt;
  
  
  React Native
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Performance and Speed
&lt;/h3&gt;

&lt;p&gt;React Native, developed by Facebook, is an open-source framework for building mobile applications using JavaScript and React.&lt;br&gt;
&lt;strong&gt;Performance:&lt;/strong&gt; React Native uses a JavaScript bridge to communicate with native modules, which can introduce some performance overhead. However, the framework provides good performance for most use cases, particularly when using native components. React Native also supports TurboModules and the new Fabric rendering engine, which aim to improve performance by reducing the overhead of the JavaScript bridge.&lt;br&gt;
&lt;strong&gt;Speed:&lt;/strong&gt; The speed of React Native applications can be influenced by the complexity of the app and the efficiency of the JavaScript code. While there is some performance overhead compared to fully native apps, React Native generally provides a smooth user experience for most applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  App Size
&lt;/h3&gt;

&lt;p&gt;React Native apps can be smaller than Flutter apps since they rely on native components and a JavaScript runtime. However, the app size can increase depending on the number of third-party libraries and assets used. Facebook and the community are continuously working on optimizing the app size by trimming unnecessary dependencies and libraries.&lt;/p&gt;

&lt;h3&gt;
  
  
  Development Ease
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Single Codebase:&lt;/strong&gt; React Native offers a single codebase for both iOS and Android, simplifying the development process and reducing the amount of duplicated code. This single codebase approach also makes it easier to maintain and update applications.&lt;br&gt;
&lt;strong&gt;Hot Reload:&lt;/strong&gt; React Native supports hot reload, which allows developers to see changes in real-time without restarting the app. This feature significantly speeds up the development process and makes it easier to iterate on designs and functionality.&lt;br&gt;
&lt;strong&gt;JavaScript and React:&lt;/strong&gt; React Native uses JavaScript and React, which are widely used and well-known technologies. This familiarity makes it easier for web developers to transition to mobile development. The extensive documentation and large number of tutorials and examples available online also make it easy for developers to get started with React Native.&lt;/p&gt;

&lt;h3&gt;
  
  
  Community and Ecosystem
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Community Support:&lt;/strong&gt; React Native has one of the largest communities among cross-platform frameworks. Facebook provides extensive documentation, tutorials, and sample projects to help developers learn and use React Native. The community also contributes to a wide range of open-source libraries and tools that support React Native development.&lt;br&gt;
&lt;strong&gt;Ecosystem:&lt;/strong&gt; React Native has a mature ecosystem with a wide range of libraries and third-party plugins available through npm. These libraries cover a wide range of functionalities, from UI components to state management and backend integration. The strong ecosystem and community support make it easy to find solutions and resources for common development tasks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Platform-Specific Capabilities
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Native Modules:&lt;/strong&gt; React Native provides access to native modules and APIs, enabling developers to implement platform-specific features and functionality. The JavaScript bridge allows for easy integration with existing native code and third-party libraries.&lt;br&gt;
&lt;strong&gt;Extensibility:&lt;/strong&gt; React Native is highly extensible, allowing developers to create custom components and libraries. The framework also supports third-party libraries and components, which can be easily integrated into React Native projects.&lt;br&gt;
&lt;strong&gt;Code Reuse:&lt;/strong&gt; React Native allows for a high degree of code reuse between platforms. While some platform-specific code may be necessary, the majority of the business logic and UI components can be shared across both iOS and Android. This code reuse significantly reduces development time and simplifies maintenance.&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Each of these frameworks has its strengths and is better suited to different types of projects and developer preferences. The best choice depends on your specific project requirements, existing expertise, and long-term goals.&lt;br&gt;
&lt;strong&gt;.NET MAUI&lt;/strong&gt; is an excellent choice for developers who are already familiar with the .NET ecosystem and want to leverage their existing skills to build cross-platform applications. The framework offers near-native performance, a rich development environment, and a growing ecosystem.&lt;br&gt;
&lt;strong&gt;Kotlin Multiplatform Mobile (KMM)&lt;/strong&gt; is ideal for Kotlin developers who want to share code between Android and iOS while maintaining native performance. The framework allows for a high degree of code reuse and deep integration with platform-specific APIs.&lt;br&gt;
&lt;strong&gt;Flutter&lt;/strong&gt; is a powerful framework for building highly performant and visually appealing applications with a single codebase. The framework's hot reload feature, comprehensive set of widgets, and extensive ecosystem make it a popular choice for cross-platform development.&lt;br&gt;
&lt;strong&gt;React Native&lt;/strong&gt; is a great option for developers who are familiar with JavaScript and React and want to build mobile applications with a single codebase. The framework offers good performance, a mature ecosystem, and a large community, making it a solid choice for many types of projects.&lt;br&gt;
In summary, the choice between &lt;strong&gt;.NET MAUI, KMM, Flutter,&lt;/strong&gt; and &lt;strong&gt;React Native&lt;/strong&gt; should be based on your specific needs, existing skills, and the requirements of your project. Each framework has its unique advantages and trade-offs, so carefully consider these factors when making your decision.&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>kotlin</category>
      <category>reactnative</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>Web Development: Rust🦀 vs Go🦫 vs Python🐍</title>
      <dc:creator>Sabbha</dc:creator>
      <pubDate>Sun, 28 Jul 2024 09:42:16 +0000</pubDate>
      <link>https://dev.to/mondal_sabbha/web-development-rust-vs-go-vs-python-2l3c</link>
      <guid>https://dev.to/mondal_sabbha/web-development-rust-vs-go-vs-python-2l3c</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foh52a1hv3g09k3cju10q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foh52a1hv3g09k3cju10q.png" alt="Image description" width="800" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's a comparison of Rust, Go, and Python for web development:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwl96lp7jsy5fh4012umt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwl96lp7jsy5fh4012umt.png" alt="Image description" width="800" height="301"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Rust:&lt;/strong&gt; Best for performance-critical applications where memory safety and concurrency are important.&lt;br&gt;
&lt;strong&gt;Go:&lt;/strong&gt; Suitable for building scalable and performant web applications, microservices, and systems that require simple concurrency.&lt;br&gt;
&lt;strong&gt;Python:&lt;/strong&gt; Ideal for rapid development, ease of use, and leveraging a mature ecosystem, especially for data-centric applications and prototyping.&lt;/p&gt;

&lt;h3&gt;
  
  
  Overall Ranking
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Python:&lt;/strong&gt; Most versatile and user-friendly, with the best tools for rapid development and a rich ecosystem.&lt;br&gt;
&lt;strong&gt;Go:&lt;/strong&gt; Strong in performance and concurrency with a straightforward and simple syntax.&lt;br&gt;
&lt;strong&gt;Rust:&lt;/strong&gt; Best for niche, performance-critical applications, but has a steeper learning curve and a less mature ecosystem for web development.&lt;/p&gt;

</description>
      <category>rust</category>
      <category>go</category>
      <category>python</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
