<?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: Déborah Mesquita</title>
    <description>The latest articles on DEV Community by Déborah Mesquita (@dmesquita).</description>
    <link>https://dev.to/dmesquita</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%2F357224%2F69e0554e-1a0c-4f07-9d5b-56bad0beb0d0.png</url>
      <title>DEV Community: Déborah Mesquita</title>
      <link>https://dev.to/dmesquita</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dmesquita"/>
    <language>en</language>
    <item>
      <title>Solution to Fish task by codility </title>
      <dc:creator>Déborah Mesquita</dc:creator>
      <pubDate>Tue, 08 Dec 2020 13:19:01 +0000</pubDate>
      <link>https://dev.to/dmesquita/solution-to-fish-task-by-codility-243h</link>
      <guid>https://dev.to/dmesquita/solution-to-fish-task-by-codility-243h</guid>
      <description>&lt;p&gt;This task is a training on how to use stacks &lt;a href="https://app.codility.com/programmers/lessons/7-stacks_and_queues/fish/"&gt;https://app.codility.com/programmers/lessons/7-stacks_and_queues/fish/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The two main important things to notice so you can complete the task are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A fish going upstream will NEVER meet a downstream fish that comes next&lt;/li&gt;
&lt;li&gt;A upstream fish can ether eat all the downstream fish or die&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is a possible solution using one stack:&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;solution&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;alive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;downstream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;direction&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;zip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;direction&lt;/span&gt; &lt;span class="o"&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;downstream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;downstream&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;downstream&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&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;# upstream fish is eaten
&lt;/span&gt;                    &lt;span class="n"&gt;alive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;alive&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
                    &lt;span class="k"&gt;break&lt;/span&gt;
                &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="c1"&gt;# upstream fish eats the other one
&lt;/span&gt;                    &lt;span class="n"&gt;downstream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
                    &lt;span class="n"&gt;alive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;alive&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;alive&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>stacks</category>
      <category>python</category>
      <category>programming</category>
    </item>
    <item>
      <title>Visualizing Machine Learning pipelines from the command line</title>
      <dc:creator>Déborah Mesquita</dc:creator>
      <pubDate>Fri, 24 Jul 2020 16:44:23 +0000</pubDate>
      <link>https://dev.to/dmesquita/visualizing-machine-learning-pipelines-from-the-command-line-3cb4</link>
      <guid>https://dev.to/dmesquita/visualizing-machine-learning-pipelines-from-the-command-line-3cb4</guid>
      <description>&lt;p&gt;Machine Learning projects sometimes look like building a brick wall: we define a stage and then build the other stages on top of it. Being able to visualize this "brick wall" is very useful, and today we'll learn how to do it using DVC.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is DVC?
&lt;/h2&gt;

&lt;p&gt;DVC is an &lt;a href="https://dvc.org/"&gt;open-source version control system&lt;/a&gt; for Machine Learning projects. Here we'll focus on the &lt;strong&gt;ML pipelines&lt;/strong&gt; feature.&lt;/p&gt;

&lt;h3&gt;
  
  
  📍 Step 1: Installing DVC
&lt;/h3&gt;

&lt;p&gt;You can do install it as a Python package. DVC &lt;strong&gt;works best with git&lt;/strong&gt; so we'll init a git project too:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;python3 &lt;span class="nt"&gt;-m&lt;/span&gt; venv .env
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;source&lt;/span&gt; .env/bin/activate
&lt;span class="gp"&gt;(.env)$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;pip3 &lt;span class="nb"&gt;install &lt;/span&gt;dvc
&lt;span class="gp"&gt;(.env)$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git init
&lt;span class="gp"&gt;(.env)$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;dvc init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  📍 Step 2: Creating the pipeline stages
&lt;/h3&gt;

&lt;p&gt;To create the pipeline stages we use the &lt;code&gt;dvc run&lt;/code&gt; command. These are the main options&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;-n : specify a name for the stage generated by this command&lt;/li&gt;
&lt;li&gt;-p : specify a set of parameter dependencies the stage depends on&lt;/li&gt;
&lt;li&gt;-d : specify a file or a directory the stage depends on&lt;/li&gt;
&lt;li&gt;-o : specify a file or directory that is the result of running the command&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We then &lt;strong&gt;create a Python script file&lt;/strong&gt; for each pipeline stage and use the &lt;code&gt;dvc run&lt;/code&gt; command with the above options to tell DVC how to run the pipeline. The parameters for each stage (&lt;code&gt;-p&lt;/code&gt; option) can be specified in a YAML file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# file params.yaml&lt;/span&gt;
&lt;span class="na"&gt;prepare&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;categories&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;comp.graphics&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;rec.sport.baseball&lt;/span&gt;
&lt;span class="na"&gt;train&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;alpha&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.9&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here is an example of a pipeline to: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Gather data&lt;/li&gt;
&lt;li&gt;Generate the features&lt;/li&gt;
&lt;li&gt;Train a model&lt;/li&gt;
&lt;li&gt;Evaluate the model&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The name of the pipeline stages are &lt;code&gt;prepare&lt;/code&gt;, &lt;code&gt;featurize&lt;/code&gt;, &lt;code&gt;train&lt;/code&gt; and &lt;code&gt;evaluate&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;(.env)$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;dvc run &lt;span class="nt"&gt;-n&lt;/span&gt; prepare &lt;span class="nt"&gt;-p&lt;/span&gt; prepare.categories &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;-d&lt;/span&gt; src/prepare.py &lt;span class="nt"&gt;-o&lt;/span&gt; data/prepared python3 src/prepare.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;(.env)$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;dvc run &lt;span class="nt"&gt;-n&lt;/span&gt; featurize &lt;span class="nt"&gt;-d&lt;/span&gt; src/featurize.py &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;-d&lt;/span&gt; data/prepared &lt;span class="nt"&gt;-o&lt;/span&gt; data/features python3 src/featurize.py &lt;span class="se"&gt;\&lt;/span&gt;
data/prepared data/features
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;(.env)$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;dvc run &lt;span class="nt"&gt;-n&lt;/span&gt; train &lt;span class="nt"&gt;-p&lt;/span&gt; train.alpha &lt;span class="nt"&gt;-d&lt;/span&gt; src/train.py &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;-d&lt;/span&gt; data/features &lt;span class="nt"&gt;-o&lt;/span&gt; model.pkl &lt;span class="se"&gt;\&lt;/span&gt;
python3 src/train.py data/features  model.pkl
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;(.env)$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;dvc run &lt;span class="nt"&gt;-n&lt;/span&gt; evaluate &lt;span class="nt"&gt;-d&lt;/span&gt; src/evaluate.py &lt;span class="nt"&gt;-d&lt;/span&gt; model.pkl &lt;span class="se"&gt;\&lt;/span&gt;
 &lt;span class="nt"&gt;-d&lt;/span&gt; data/features &lt;span class="nt"&gt;--metrics-no-cache&lt;/span&gt; scores.json &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--plots-no-cache&lt;/span&gt; plots.json python3 src/evaluate.py &lt;span class="se"&gt;\&lt;/span&gt;
model.pkl  data/features scores.json plots.json
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  📍 Step 3: Visualizing the pipeline
&lt;/h3&gt;

&lt;p&gt;We can run the &lt;code&gt;dvc dag&lt;/code&gt; command anytime to visualize the pipeline. This is the pipeline after creating all the stages above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;dvc dag
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         +---------+      
         | prepare |      
         +---------+      
              *           
              *           
              *           
        +-----------+     
        | featurize |     
        +-----------+     
         **        **     
       **            *    
      *               **  
+-------+               * 
| train |             **  
+-------+            *    
         **        **     
           **    **       
             *  *         
        +----------+      
        | evaluate |      
        +----------+  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And that's it! &lt;br&gt;
You can see the whole code for this pipeline &lt;a href="https://github.com/dmesquita/dvc_pipelines_and_experiments_tutorial"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you want a &lt;strong&gt;more in depth guide&lt;/strong&gt; on building pipelines you can check this other article: &lt;a href="https://towardsdatascience.com/the-ultimate-guide-to-building-maintainable-machine-learning-pipelines-using-dvc-a976907b2a1b"&gt;The ultimate guide to building maintainable Machine Learning pipelines using DVC&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>datascience</category>
      <category>productivity</category>
      <category>commandline</category>
    </item>
  </channel>
</rss>
