<?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>Forem: Clébio Júnior</title>
    <description>The latest articles on Forem by Clébio Júnior (@juniorcl).</description>
    <link>https://forem.com/juniorcl</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%2F455526%2F10a9ce5c-fc9e-46a6-83b1-d4eb20be931a.jpeg</url>
      <title>Forem: Clébio Júnior</title>
      <link>https://forem.com/juniorcl</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/juniorcl"/>
    <language>en</language>
    <item>
      <title>Going Beyond Accuracy: Understanding the Balanced Accuracy, Precision, Recall and F1-score.</title>
      <dc:creator>Clébio Júnior</dc:creator>
      <pubDate>Wed, 22 Oct 2025 17:01:08 +0000</pubDate>
      <link>https://forem.com/juniorcl/going-beyond-accuracy-understanding-the-balanced-accuracy-precision-recall-and-f1-score-4kl2</link>
      <guid>https://forem.com/juniorcl/going-beyond-accuracy-understanding-the-balanced-accuracy-precision-recall-and-f1-score-4kl2</guid>
      <description>&lt;p&gt;&lt;em&gt;Tutorial about metrics which are used for machine learning model validations. The metrics covered in this tutorial are balanced accuracy, precision, recall and F1-score. This same tutorial may be read in a portuguese version &lt;a href="https://medium.com/data-hackers/indo-al%C3%A9m-da-acur%C3%A1cia-entendo-a-acur%C3%A1cia-balanceada-precis%C3%A3o-recall-e-f1-score-c895e55a9753" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;During a data science project one of the most wished steps is the development of a machine learning model. In this step there's training and validation of the model, and one of the most used metrics to validate the machine learning model is &lt;strong&gt;accuracy&lt;/strong&gt;. However, how far can the accuracy show how effective the model was in classifying two or more classes?&lt;/p&gt;

&lt;p&gt;Therefore, in this post other metrics will be described. They will help you to get other perspectives on the performance of your model, especially with unbalanced databases, in other words, databases with more numbers of a class than others. Here will be covered the metrics &lt;strong&gt;balanced accuracy&lt;/strong&gt;, &lt;strong&gt;precision&lt;/strong&gt;, &lt;strong&gt;recall&lt;/strong&gt; and &lt;strong&gt;F1-score&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;All the metrics described in this post result in a score between 0 and 1. Where 0 is the worst result and 1 is an excellent result. However, Each metric has different interpretation.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Confusion Matrix
&lt;/h2&gt;

&lt;p&gt;Before to understand how the metrics work, you need to know what is a confusion matrix. Because it will be our basis for the calculations of each metric.This matrix show which are the predictions of each class "yes" or "no". Where the rows are the true classes and the columns are the predictions. So it's possible to classify how the classes were predicted. The table 1 shows this kind of matrix.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;No&lt;/th&gt;
&lt;th&gt;Yes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;No&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;TN&lt;/td&gt;
&lt;td&gt;FP&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Yes&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;FN&lt;/td&gt;
&lt;td&gt;TP&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Table 1:&lt;/strong&gt; &lt;em&gt;Confusion matrix where the "no" and "yes" classes are related to the predictions made by a machine learning model. TN, FP, FN, and TP are acronyms that stand for "true negative", "false positive", "false negative" and "true positive" respectively.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That said, the correct classifications of the “no” class are defined as true negatives (TN), while the correct classifications of the “yes” class are called true positives (TP). Misclassifications of “no” as “yes” are referred to as false positives (FP), and incorrect classifications of “yes” as “no” are known as false negatives (FN).&lt;/p&gt;

&lt;p&gt;Table 2 shows the same Table 1, now with example values to illustrate a machine learning model from a data science project for predicting fraudulent banking transactions. The values 101,668, 3, 36, and 95 represent, respectively, TN, FN, FP, and TP. For more information about the referenced data science project, visit the provided &lt;a href="https://github.com/juniorcl/transaction-fraud-detection" rel="noopener noreferrer"&gt;link&lt;/a&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;No&lt;/th&gt;
&lt;th&gt;Yes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;No&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;101668&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Yes&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;36&lt;/td&gt;
&lt;td&gt;95&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Table 2:&lt;/strong&gt; &lt;em&gt;Confusion matrix with the results of a machine learning model for predicting fraudulent banking transactions. The values 101,668, 3, 36, and 95 represent, respectively, the number of TN, FP, FN, and TP.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Balanced Accuracy
&lt;/h2&gt;

&lt;p&gt;Accuracy basically calculates all correct predictions (TP and TN) divided by the total number of predictions, that is, all correct and incorrect ones (TP + TN + FP + FN), as shown in Equation 1. However, when there is a highly imbalanced class, accuracy is not a good metric to use. As can be seen in the equation, the high number of TN classifications can mask the low number of TP classifications — giving a misleading impression that the model is performing well in classifying the data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F73kcufq9hatp1jp0dax9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F73kcufq9hatp1jp0dax9.png" alt="Accuracy Equation" width="367" height="51"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Equation 1:&lt;/strong&gt; &lt;em&gt;Accuracy.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;An alternative to accuracy is &lt;strong&gt;balanced accuracy&lt;/strong&gt;, which is not affected by class imbalance because it is calculated based on the &lt;strong&gt;true positive rate&lt;/strong&gt; and the &lt;strong&gt;true negative rate&lt;/strong&gt;, as shown in &lt;strong&gt;Equation 2&lt;/strong&gt;. This approach provides a more reliable measure of the model’s performance across both classes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Frxau3k0taz14b4s02vrx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Frxau3k0taz14b4s02vrx.png" alt="Balanced Accuracy Equation" width="530" height="57"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Equation 2:&lt;/strong&gt; &lt;em&gt;Balanced Accuracy.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To illustrate, the values of accuracy and balanced accuracy will be calculated using the data from Table 2. The resulting accuracy is 0.9996, which might initially suggest that the model correctly classified almost all instances and is performing exceptionally well. However, most of the correct predictions come from the majority class, which skews the result.&lt;/p&gt;

&lt;p&gt;When we use balanced accuracy, which gives equal weight to the performance on each class, the value is 0.8626. This provides a more realistic measure of how well the model performs across both classes.&lt;/p&gt;

&lt;p&gt;Even with balanced accuracy, we still only get a global view of overall correctness, so we cannot see how well the model performed on a specific class of interest. In our example, how well did the model identify fraudulent transactions? What percentage of the “yes” class was classified correctly?&lt;/p&gt;

&lt;h2&gt;
  
  
  Precision
&lt;/h2&gt;

&lt;p&gt;We now understand balanced accuracy and how it provides a global view of the model’s performance across all classes. However, it is also important to examine the model’s classification ability in more detail. In our fraud detection example, how well can the model correctly identify a transaction as truly fraudulent?&lt;/p&gt;

&lt;p&gt;The metric used to answer this question is precision, which measures the percentage of correct positive predictions made by the model. This metric relates the number of true positives (TP) to the sum of TP and false positives (FP), as shown in Equation 3.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F5by1e2z366yyr8p3budb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F5by1e2z366yyr8p3budb.png" alt="Precision Equation" width="237" height="51"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Equation 3:&lt;/strong&gt; &lt;em&gt;Precision.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To better interpret this metric, imagine you have a distant target to hit. If you take 100 shots and hit the target 70 times, your precision is 70%. The same logic applies to interpreting the precision of a machine learning model. In our example from Table 2, the precision is 0.9694 or 96.94%. This means that for every 100 positive predictions, the model correctly identifies approximately 97.&lt;/p&gt;

&lt;h2&gt;
  
  
  Recall
&lt;/h2&gt;

&lt;p&gt;In addition to precision, which shows how well the model can differentiate between classes, it is also important to know how many fraudulent transactions were correctly identified in our example from Table 2. For this reason, we consider the recall metric, also known as sensitivity. This metric measures how well a model can recognize instances of a specific class. Recall is calculated by dividing the number of true positives (TP) by the sum of TP and false negatives (FN) — in other words, the “yes” instances that were incorrectly classified.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Festaqln5bzbmwak698w7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Festaqln5bzbmwak698w7.png" alt="Recall Equation" width="204" height="51"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Equation 4:&lt;/strong&gt; &lt;em&gt;Recall&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In our example from Table 2, the recall value is 0.7252 or 72.52%. This result shows that the model correctly classified approximately 73% of the “yes” instances. Therefore, this metric can be used to report the percentage of fraudulent transactions that the model is able to correctly identify.&lt;/p&gt;

&lt;h2&gt;
  
  
  F1 Score
&lt;/h2&gt;

&lt;p&gt;After reviewing precision and recall, you might be thinking that these metrics are important for evaluating model performance. After all, the better a model can differentiate between classes and correctly predict the “yes” class of interest, the better its overall performance.&lt;/p&gt;

&lt;p&gt;So, how can we take both metrics into account when assessing a model’s performance?&lt;/p&gt;

&lt;p&gt;In this context, one metric we can use is the F1 score. The F1 score is basically the harmonic mean of precision and recall, as shown in Equation 5. In the example from Table 2, the F1 score is 0.8297. This metric can be particularly useful when developing new models to determine which one achieves the best performance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F926h5p58com4mjtzuali.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F926h5p58com4mjtzuali.png" alt="F1 Score Equation" width="606" height="51"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Equation 5:&lt;/strong&gt; &lt;em&gt;F1 Score&lt;/em&gt;&lt;/p&gt;

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

&lt;p&gt;In this post, we explored several metrics commonly used to evaluate the performance of a machine learning model. We learned that &lt;strong&gt;accuracy&lt;/strong&gt; is not always the best validation metric and can sometimes give a misleading impression of the model’s effectiveness.&lt;/p&gt;

&lt;p&gt;For imbalanced classes, a more appropriate metric is &lt;strong&gt;balanced accuracy&lt;/strong&gt;, which provides a global view of the model’s performance across all classes.&lt;/p&gt;

&lt;p&gt;To get a more detailed view of individual classes, we rely on &lt;strong&gt;precision&lt;/strong&gt;, which shows how many predictions the model got right, and &lt;strong&gt;recall&lt;/strong&gt;, which indicates how many instances of a particular class were correctly identified by the model. To evaluate both metrics simultaneously, we use the &lt;strong&gt;F1 score&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Finally, I hope you enjoyed this post and gained a better understanding of alternative metrics to assess your models. See you next time!&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>machinelearning</category>
      <category>metrics</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Why it's not a good idea to start with complex machine learning models: a personal experience</title>
      <dc:creator>Clébio Júnior</dc:creator>
      <pubDate>Sun, 23 Aug 2020 16:46:15 +0000</pubDate>
      <link>https://forem.com/juniorcl/why-it-s-not-a-good-idea-start-with-complex-models-244i</link>
      <guid>https://forem.com/juniorcl/why-it-s-not-a-good-idea-start-with-complex-models-244i</guid>
      <description>&lt;p&gt;When I started studying data science, I became fascinated about neural networks and their power for such complicated applications. As examples, there are applications in computer vision and natural language processing (NLP). Because of their power, I just wanted to start using them in every single problem. But I had to calm down! Sometimes a simple model can get on good score.&lt;/p&gt;

&lt;p&gt;In this post I guide you in my experience as a beginner in my first data science challenge and how it helped me to grow up as a student and a data scientist. I'll never forget the power of a simple linear regression model!&lt;/p&gt;

&lt;h1&gt;
  
  
  The Challenge
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://codenation.dev/" rel="noopener noreferrer"&gt;Condenation&lt;/a&gt; is a website which sometimes organizes challenges as a first step towards accelerating in different areas, one of them is about data science. The last data science challenge was about a prediction of ENEM (brazilian exam to get in the public university) student score in math.&lt;/p&gt;

&lt;p&gt;I started it so excited! But I was blind just because I didn't try any other model unless Random Forest and Neural Network to predict the math score. I made a preprocessing to replace some NaN values and selected some features with high correlation. After it, I did a hard work with &lt;a href="https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.RandomizedSearchCV.html" rel="noopener noreferrer"&gt;RandomizedSearchCV&lt;/a&gt; to select best parameters. Despite all the hard work I had done, it was unable to reach 90% and to join to the Codenation. So I got frustrated and I gave up on me.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fbj7nreodmqxzlijbfftf.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fbj7nreodmqxzlijbfftf.gif" alt="Alt Text" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;A blessing in disguise..&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Recently I met the same database at &lt;a href="https://www.kaggle.com/davispeixoto/codenation-enem2" rel="noopener noreferrer"&gt;Kaggle&lt;/a&gt;. It's been a while since I had accept the challenge, so I tried it again. As you can read below I will show a new approach to the challenge and how to judge a simple model as weak without even using it. It was a big mistake and a great learning experience.&lt;/p&gt;

&lt;h1&gt;
  
  
  A New Approach
&lt;/h1&gt;

&lt;p&gt;Here I won't describe everything I did, for example in relation to data preprocessing. But if you want to see my notebook, you can access it in &lt;a href="https://www.kaggle.com/juniorcl/mathenemscores-linearregression" rel="noopener noreferrer"&gt;kaggle&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;First of all, I checked the database and if it has taken some NaN values. These values were replaced to 0, because I had to deal with it as students dropouts. Afterwards, I realized that there were some correlation among these features. My idea was to get the highest features and use them to predict the math score. The heatmap below shows these correlations using Pearson coefficient.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzxsl4295g3lpqc422wut.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzxsl4295g3lpqc422wut.png" alt="Alt Text" width="650" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see, they have a high correlations. So I decided to use them as a predictor feature in a simple linear regression model, as shown below.&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="n"&gt;X&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;df_train_filled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;NU_NOTA_COMP5&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;NU_NOTA_MT&lt;/span&gt;&lt;span class="sh"&gt;'&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="n"&gt;df_train_filled&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;NU_NOTA_MT&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;train_test_split&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;test_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.25&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;lr&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;normalize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;lr&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_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;lr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;score&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_test&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using a simple train and test split we've got a accuracy of 90%. This accuracy was better than random forest and neural networks models. But maybe you are wondering: "Did you just use part of the database? For a complete understanding, it's needed to use cross validation!". Ok, ok.. You're right! I did it too, as you can see below.&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="c1"&gt;# making scores
&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;make_scorer&lt;/span&gt;&lt;span class="p"&gt;(&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;r2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;make_scorer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r2_score&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 

&lt;span class="n"&gt;cvs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;cross_validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;estimator&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;normalize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&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="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="o"&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;cv&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;verbose&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;scoring&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;mae&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;mae&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;r2&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;r2&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I used the mean absolute error and 

&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;R2R^2&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;R&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 score to evaluate the model. The mean scores were 50.027 and 0.902, respectively. Maybe this model can predict the math score with 90% of score for a test database. So I can be happy and try to make my submission! No, no..&lt;/p&gt;

&lt;p&gt;Unfortunately, there is not a possibility to make a submission in Kaggle or on the original website. The Codenation closed a long time ago, so I have to wait for a new chance in the future.&lt;/p&gt;

&lt;h1&gt;
  
  
  However, what can we learn from it?
&lt;/h1&gt;

&lt;p&gt;It's important to notice that even using random forest and neural networks models I could make some better preprocessing or selected other features and get a good score. Yes, it's right! But this experience was important to me, because I could learn and become a better data scientist. &lt;/p&gt;

&lt;p&gt;Even you think that model is so simple to do a hard task, you should give it a chance. Maybe it can't get to a high score or result. However it can become a start point to verify if others models is helping you improving the scorer.&lt;/p&gt;

&lt;p&gt;I hope this post could help you!!&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>python</category>
      <category>machinelearning</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
