<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Amine on Medium]]></title>
        <description><![CDATA[Stories by Amine on Medium]]></description>
        <link>https://medium.com/@aminey?source=rss-e87127a3cbe5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Amine on Medium</title>
            <link>https://medium.com/@aminey?source=rss-e87127a3cbe5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 18:28:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aminey/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[My Experience Deploying an App With Streamlit Sharing]]></title>
            <link>https://medium.com/geekculture/my-experience-deploying-an-app-with-streamlit-sharing-471e49905247?source=rss-e87127a3cbe5------2</link>
            <guid isPermaLink="false">https://medium.com/p/471e49905247</guid>
            <category><![CDATA[web-app-development]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[streamlit]]></category>
            <dc:creator><![CDATA[Amine]]></dc:creator>
            <pubDate>Mon, 08 Mar 2021 11:11:24 GMT</pubDate>
            <atom:updated>2021-03-25T22:31:01.472Z</atom:updated>
            <content:encoded><![CDATA[<h4>Build a multi-functional app with good memory management and avoid memory leak</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TO178H4Cy_kWffb6" /><figcaption>Photo by <a href="https://unsplash.com/@ademay?utm_source=medium&amp;utm_medium=referral">Adem AY</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This is not a tutorial of how to use streamlit, you can find great tutorials in the <a href="https://docs.streamlit.io/en/stable/">streamlit docs</a> and <a href="https://medium.com/search?q=streamlit%20tutorial">medium articles</a>. This is the summary of my trial and error deploying an app and debugging the most frequent bugs with streamlit sharing.</p><p>For those who don’t know <a href="https://streamlit.io/">streamlit</a>, it’s an open-source app framework for data scientists to deploy their data apps in a few lines of code. The use of streamlit is very easy. Here, we are talking about building the app, because deploying the app is another story. <strong>It’s as they call it:<em> Ridiculously Easy</em>.</strong></p><blockquote>Now, let’s dive into the main topic: <strong>How to debug the most frequent bugs you face while building and deploying an app with streamlit?</strong></blockquote><p>The tips I will share might be a piece of cake for people coming from computer science background. However, for data scientists that mostly work with jupyter notebooks, <strong>who are the potential streamlit users</strong>, this article might be useful because it highlights the importance of object oriented programming in building a memory-friendly clean pipeline.</p><h3>My Web App:</h3><p><strong>The app predicts diseases in cassava plants: </strong><a href="https://share.streamlit.io/amiiney/cld-app-streamlit/main/app.py"><strong>Web App</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*kHumPoqbTtSgORFmSnvi9A.gif" /><figcaption><strong>Figure 1.</strong> GIF of my App’s page: Select an image to discover the app’s features.</figcaption></figure><p>The gif above shows the functionality of my App: <strong>You upload/select a Cassava plant image and a deep learning model predicts the disease in the plant image with a detailed report.</strong></p><p><strong><em>The idea behind the app:</em></strong> I participated in a kaggle competition: <a href="https://www.kaggle.com/c/cassava-leaf-disease-classification">Cassava leaf disease prediction competition</a> where we had to train models to predict diseases in cassava plants. I had the model and the weights ready, so I decided to create <a href="https://share.streamlit.io/amiiney/cld-app-streamlit/main/app.py">my first streamlit App</a>.</p><p>If you’d like to learn more about the training process of the model, please check my article:</p><p><a href="https://aminey.medium.com/how-to-train-ml-models-with-mislabeled-data-cf4bb353b3d9">How To Train ML Models With Mislabeled Data</a></p><h3>Demo App option</h3><p>For inspiration, I checked many apps in the <a href="https://streamlit.io/gallery">streamlit app gallery</a>, and realized that as a user, it’s very important to provide the user with a demo option to test the app.</p><p>Many apps are great but they require the user to upload a file for the app to run, most users would just skip. However, <strong>if you provide the user with a demo option, then there is a solid chance that user would test your app and discover all the features it offers.</strong></p><p>An example of the demo version of my app. I provide the user with 3 built-in images to select:</p><figure><img alt="A screenshot of my webapp to show the options I give to the users" src="https://cdn-images-1.medium.com/max/1024/1*jJW1X1mabo4UQnx0ePSpKQ.png" /><figcaption><strong>Figure 2. </strong>Demo app provides the user with 3 images to select for trial</figcaption></figure><p>Adding a demo to your app can increase your memory consumption, that’s why it’s important to learn how to efficiently manage your RAM to avoid memory leaks.</p><h3>Memory management: Make the most out of 800MB of RAM</h3><p>With streamlit sharing, Apps get up to 1 CPU, 800 MB of RAM, and 800 MB. This is a generous compute power compared to Heroku’s free tier with only 512 RAM. The memory is the variable we want to optimize, especially for multi-functional apps. <strong>We want our app to have as many features as possible with the minimum memory consumption.</strong></p><p>You can see in <strong><em>figure 1</em></strong> that my App has many elements that might consume a lot of memory:</p><ul><li><strong>Many dependencies:</strong> OpenCV, matplotlib and albumentations for image preprocessing, Pytorch and torchvision for modeling…</li><li><strong>Images:</strong> Image data occupy more space in the RAM than text or tabular data.</li><li><strong>Deep learning model:</strong> Loading the training weights (size 100MB).</li><li><strong>Many features:</strong> <strong>(1)</strong> <em>select/upload an image</em> <strong>(2)</strong> <em>display the image</em> <strong>(3)</strong> <em>print the prediction result</em> <strong>(4)</strong> <em>display the grad-cam image </em><strong>(5)</strong> <em>print</em> <em>the class predictions table. </em><strong>Every executed feature will lead to an object stored in the memory.</strong></li></ul><p>The ideal memory usage should be something like the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZWza9IzVGoCamdTnryDm3A.png" /><figcaption><strong>Figure 3.</strong> App memory usage: (1) Installing dependencies/Libraries (Exponential phase) (2) App running without memory consumption (plateau). [Image by Author]</figcaption></figure><p>As your app boots up, it consumes a base amount of RAM when installing the dependencies you cite in the <a href="https://github.com/Amiiney/cld-app-streamlit/blob/main/requirements.txt">requirements.txt</a> file that are required for your app to run.</p><p>The rapid increase in the exponential phase is followed by a plateau phase where your app is running correctly hovering around a stable point without increasing its memory consumption.</p><blockquote>The difference between your RAM limit (800MB) and the plateau phase is important. The lower it plateaus, the more users your app can handle at the same time.</blockquote><p>More information about <a href="https://www.cloudbees.com/blog/debugging-a-memory-leak-on-heroku/">debugging memory leak</a>.</p><h3><strong>TIP N°1: Don’t install unnecessary libraries</strong></h3><p>If you are a jupyter notebook user, you probably always start your work by importing dozens of libraries, sometimes you don’t use most of them since you have 15GB of RAM in a colab notebook and keeping them won’t hurt. In case you deploy an app with streamlit<em> </em>you only have 800MB of RAM.</p><p><strong>Here are 2 examples of how I reduced the number of libraries:</strong></p><ul><li><strong><em>Avoid ‘repetitive’ libraries:</em></strong> I was using both Pillow and OpenCV libraries for image preprocessing. <strong>You can perfectly do the job with one of them.</strong> So I had to convert all the Pillow codes and stick to OpenCV.</li><li><strong><em>Avoid ‘intermediary’ libraries:</em></strong> I was using <a href="https://pypi.org/project/timm/">Timm library</a> to import my pytorch model. Well, Timm library itself imports the model from the <a href="https://pytorch.org/vision/stable/index.html">Torchvision library</a>. So, <strong>I could perfectly drop the Timm library and import directly from Torchvision</strong>.</li></ul><h3>TIP N°2: Avoid memory leak</h3><p>The mistake that I was making, and that most jupyter notebook users would make, is to store the same data in many variables throughout the notebook, which is translated to an unnecessary memory consumption. <strong>The ideal thing to do is to wrap all your variables inside of python functions or classes</strong> to make sure each individual variable is read and stored in the memory only once.</p><p>This applies for a single use, however, our app is meant to be used multiple times by multiple users. <strong>Every time a user uses the app, your python script is run in the backend and your python objects are stored in the memory.</strong></p><blockquote>I realized that after sending my app to some users to test it, the app crashes before the 4th user could open it.</blockquote><figure><img alt="A figure showing the exponential and plateau phase of web app usage, with the app exceeding the RAM limit." src="https://cdn-images-1.medium.com/max/1024/1*qkPWySxyZFFMgzJHdKenFw.png" /><figcaption><strong>Figure 4. </strong>Memory leak: The accumulation of not deleted python objects by the users lead to a constant increase in memory consumption and exceeding the RAM limit. [Image by Author]</figcaption></figure><p>As I mentioned earlier, my app uses a heavy deep learning model, the model’s weights alone consume 100MB of memory. So storing the model in memory repeatedly made my app crash after 3 trials.</p><p>The solution to this is very easy, wrap all your variables inside of a function or a class. After the execution of the code, <strong>delete every single variable (images, data-frames, models, weights…).</strong></p><blockquote>You can check the code in my <a href="https://github.com/Amiiney/cld-app-streamlit/blob/main/app.py">app.py script</a>. All the variables are wrapped in the <strong><em>deploy()</em></strong> function. After the execution of the function, all the variables are deleted with the <strong><em>del</em></strong> keyword.</blockquote><p>If you don’t free your memory when you’re done using it, it can result in a memory leak. Sometimes deleting the used variables is not enough, especially if your variable was copied from a class or a function. This might affect your App at the long term.</p><p>To make sure all the used data has been freed from the memory, <a href="https://docs.python.org/3/library/gc.html">use garbage collection module in python</a>. Running a garbage collection process cleans up a huge amount of unused objects from the memory.</p><pre>#Import the garbage collection module<br>Import gc</pre><pre>#Enable garbage collection<br>gc.enable()</pre><pre>#Clean up the memory from unused objects<br>gc.collect()</pre><p>To learn more about garbage collection, I recommend reading this article: <a href="https://stackify.com/python-garbage-collection/">Python Garbage Collection: What It Is and How It Works</a>.</p><h3>Final thoughts</h3><p>I share in this article some basic tips to improve the memory management of Web Apps. This is my first app, so any advice or tips on how to improve the performance of the app is more than welcome. You can find the code in <a href="https://github.com/Amiiney/cld-app-streamlit">my GitHub repository</a>, feel free to contribtue to the project with pull requests.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=471e49905247" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/my-experience-deploying-an-app-with-streamlit-sharing-471e49905247">My Experience Deploying an App With Streamlit Sharing</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Train ML Models With Mislabeled Data]]></title>
            <link>https://aminey.medium.com/how-to-train-ml-models-with-mislabeled-data-cf4bb353b3d9?source=rss-e87127a3cbe5------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf4bb353b3d9</guid>
            <category><![CDATA[kaggle]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Amine]]></dc:creator>
            <pubDate>Wed, 24 Feb 2021 11:55:24 GMT</pubDate>
            <atom:updated>2021-02-24T16:08:42.775Z</atom:updated>
            <content:encoded><![CDATA[<h4>3 Tips on how to train machine learning models efficiently when your data is noisy and mislabeled…</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2ccJaJpQdCuFhNfs" /><figcaption>Photo by <a href="https://unsplash.com/@anexdr?utm_source=medium&amp;utm_medium=referral">Alex Chumak</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this article, I would like to talk about 3 tricks that helped me to efficiently train models and win a silver medal in <a href="https://www.kaggle.com/c/cassava-leaf-disease-classification">a kaggle competition</a> where the dataset was mislabeled and contained a significant amount of noise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*53XGbk4nxI8Mwf9I-SLW4A.png" /><figcaption>Leaderboard position of the Cassava Leaf Disease Classification competition.</figcaption></figure><p>By using those 3 tricks, I managed to deal with the noisy data and finish in the <a href="https://www.kaggle.com/c/cassava-leaf-disease-classification/leaderboard"><strong>114th position out of 3900 teams</strong></a> in this competition.</p><blockquote>Rule n° 1 in data science: Garbage In = Garbage Out.</blockquote><p>Mislabeled data is part of real world data, not all the datasets are clean. Most datasets tend to have some amount of noise which can be challenging when training a machine learning model. The good news is that the <strong><em>Garbage In = Garbage Out</em></strong> rule can be overcome with some tricks that can help your model adapt to the <em>mislabeled data.</em></p><h3>A brief introduction to the dataset:</h3><p><a href="https://www.kaggle.com/c/cassava-leaf-disease-classification"><strong><em>Cassava leaf disease prediction</em></strong></a><strong><em>:</em></strong> It’s a computer vision competition with a dataset of 21,367 labeled images of cassava plants. The aim of the competition was to classify each cassava image into four disease categories or a fifth category indicating a healthy leaf.</p><figure><img alt="5 images representing cassava plants with 4 different diseases 1 healthy plant" src="https://cdn-images-1.medium.com/max/814/1*fNxnOshgSyxwf0IZbs73uw.png" /><figcaption><strong>Figure 1. </strong>Cassava plant classes 4 diseases and one healthy class: CBB, Healthy, CBSD, CGM and CMD [Image by Author]</figcaption></figure><p>After a quick exploratory data analysis, I realized that some of the images were mislabeled, let’s have the example of the 2 images below:</p><figure><img alt="2 images of cassava plants. the first image has dead leaves, the second one has healthy leaves" src="https://cdn-images-1.medium.com/max/817/1*ZOcaaASpz2f4kIZ2nqRD8g.png" /><figcaption><strong>Figure 2.</strong> An example of a mislabeled image (left) and a correctly labeled image (right) [Image By Author]</figcaption></figure><p>We can clearly see that the 1st image contains diseased leaves while the 2nd one has healthy leaves . Well, both images were labeled as ‘healthy’ in this dataset, which makes the task of the model harder since it has to extract and learn the features of healthy and diseased leaves and assign them to the same class: <em>Healthy</em>.</p><p>In the following section, I would like to talk about 3 tricks I found useful to deal with noisy datasets:</p><h3>1- Bi-Tempered loss function:</h3><p>Picking the right loss function is very critical in machine learning. It depends a lot on your data, task and metric. In this case, we have a multi-class classification <em>(5 classes)</em> with categorical accuracy as a metric. So, the first loss function that comes to mind is <a href="https://peltarion.com/knowledge-center/documentation/modeling-view/build-an-ai-model/loss-functions/categorical-crossentropy"><strong>categorical cross-entropy</strong></a>.</p><p>However, we have a mislabeled dataset and the cross-entropy loss is very sensitive to outliers. Mislabeled images can stretch the decision boundaries and dominate the overall loss.</p><p>To solve this problem, <a href="https://ai.googleblog.com/2019/08/bi-tempered-logistic-loss-for-training.html">Google AI researchers introduced a “bi-tempered” generalization of the logistic loss</a> endowed with two tunable parameters that handle those situations well, which they call “temperatures” — <em>t1</em>, which characterizes boundedness, and <em>t2</em> for <a href="https://en.wikipedia.org/wiki/Heavy-tailed_distribution">tail-heaviness</a>.</p><p>It’s basically a cross-entropy loss with 2 new tunable parameters <em>t1</em> and <em>t2</em>. The standard cross-entropy can be recovered by setting both <em>t1</em> and <em>t2</em> equal to 1.</p><p>So, what happens when we tune t1 and t2 parameters?</p><figure><img alt="Examples of the decision boundaries of models using logistic loss (stretched boundaries) and Bi-Tempered loss (adjusted boundaries) functions" src="https://cdn-images-1.medium.com/max/1024/1*ErpntL4TOloH2Z5Myrr8DA.png" /><figcaption><strong>Figure 3.</strong> Difference in decision boundaries between logistic loss (cross-entropy loss) and Bi-Tempered loss Source: <a href="https://ai.googleblog.com/2019/08/bi-tempered-logistic-loss-for-training.html">https://ai.googleblog.com/2019/08/bi-tempered-logistic-loss-for-training.html</a></figcaption></figure><p>Let’s understand what’s happening here:</p><ul><li><strong>With small margin noise:</strong> The noise stretched the decision boundary in a heavy tailed form. This was solved with the Bi-Tempered loss by tuning the t2 parameter from <em>t2=1 to t2=4.</em></li><li><strong>With large margin noise:</strong> The large noise stretched the decision boundary in a bounded way, covering more surface than the heavy tail in the case of small margin noise. The Bi-Tempered loss solved this by tuning the t1 parameter from <em>t1=1 to t1=0.2.</em></li><li><strong>With random noise:</strong> Here, we can see both heavy tails and bounded decision boundaries, so both <em>t1</em> and <em>t2</em> are adjusted in the Bi-Tempered loss.</li></ul><p>The best way to finetune the <em>t1</em> and <em>t2</em> parameters is by plotting your model’s decision boundary and checking if your decision boundary is heavy tailed, bounded or both, then tweak the t1 and t2 parameters accordingly.</p><p>If you are dealing with tabular data, you can use the <strong><em>Plot_decision_regions()</em></strong> function to visualize your model’s decision boundaries.</p><pre>#Import package<br>from mlxtend.plotting import plot_decision_regions</pre><pre># Plot decision boundary<br>plot_decision_regions(x=x_test, y=y_test, clf=model, legend=2)<br>plt.show()</pre><p>You can learn more about the Bi-Tempered loss in the <a href="https://ai.googleblog.com/2019/08/bi-tempered-logistic-loss-for-training.html">Google AI blog</a> and their <a href="https://github.com/google/bi-tempered-loss">github repository</a>.</p><h3>2- Self Distillation:</h3><p>If you are already familiar with knowledge distillation where knowledge transfer takes place from a teacher to a student model, self distillation is a very similar concept.</p><p>This new concept was introduced in the paper: <a href="https://arxiv.org/pdf/1905.08094.pdf">Be Your Own Teacher: Improve the Performance of Convolutional Neural Networks via Self Distillation</a>. The idea is so simple:</p><blockquote>Self Distillation: You train your model and then you retrain it using itself as a teacher.</blockquote><p>The paper discusses a more advanced approach that includes several loss functions and some architecture modifications (Additional bottleneck and fully connected layers). In this article. I’d like to introduce a much simpler approach.</p><p>I read about this approach in the <a href="https://www.kaggle.com/c/plant-pathology-2020-fgvc7/discussion/154056">first place solution</a> of the plant pathology competition on kaggle, where the winner team used self-distillation to deal with the noisy dataset. You can check the code in <a href="https://github.com/alipay/cvpr2020-plant-pathology">their github repository.</a></p><p>Self Distillation in 3 steps:</p><ul><li><strong>1-</strong> Split your dataset to <em>k</em> folds cross-validation.</li><li><strong>2-</strong> Train model 1 to predict the out of folds predictions.</li></ul><figure><img alt="A diagram representing a dataset split to 5 folds cross-validation fed to a neural networks model that predicts the out of folds predictions" src="https://cdn-images-1.medium.com/max/684/1*c_9dJrD2pIFAxuJeg0bs3g.png" /><figcaption><strong>Figure 4. </strong>The dataset is split to 5 folds cross-validation.<strong> </strong>Model 1 predicts out of fold predictions. [Image by Author]</figcaption></figure><ul><li><strong>3-</strong> After saving the out of folds predictions predicted by our model, we load them and blend them with the original labels. The blending coefficients are tunable, the original labels should have a higher coefficient.</li></ul><figure><img alt="A dataset split to 5 fold cross validation, the labels are blend with the out of folds predictions from the previous figure. The new dataset is fed to the neural networks model" src="https://cdn-images-1.medium.com/max/773/1*Y1gEAuoA5ZR4lJSBPx7IQA.png" /><figcaption><strong>Figure 5. </strong>Model 2 uses out of fold predicitons (OOF) from Model 1 to improve its performance. [Image by Author]</figcaption></figure><p>The out of fold predictions here are class probabilities predicted by model 1:</p><ul><li>In this particular example we have a multiclass classification with 5 classes <strong>[0,1,2,3,4]</strong>.</li><li>The labels are one hot encoded. Class 2 is represented as <strong>[0,0,1,0,0]</strong>.</li><li><strong><em>Model 1</em></strong> predicted the class 2 correctly: <strong>[0.1, 0.1 ,0.4 ,0.1 ,0.3].</strong> Giving it a probability of 0.4, higher than the other classes. But, it also gave class 4 a high probability of 0.3.</li><li><strong><em>Model 2</em></strong> will use this information to improve its predictions.</li></ul><h3>3- Ensemble learning:</h3><p>Ensemble learning is well known to improve the quality of predictions in general. In the case of noisy datasets it can be very helpful because each model has a different architecture and learns different patterns.</p><p>I was planning to try Vision Transformer models released by Google AI in the paper: <a href="https://arxiv.org/abs/2010.11929">An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale</a>, and this competition was the perfect place to try and learn more about them since they introduce a new concept in computer vision that is different than convolutional neural networks that are dominating the field.</p><p>In short, the ensemble of a vision transformer model with 2 different CNN architectures improves the predictions quality of single models:</p><figure><img alt="A diagram representing a dataset split to 5 folds cross-validation fed to 3 different neural networks: Vision transformer, resnext50_32d_4d and efficientnet B3" src="https://cdn-images-1.medium.com/max/853/1*krM1KKrBgsK_DiNUylJPSQ.png" /><figcaption><strong>Figure 6.</strong> Ensemble of 3 different models: VitBase-16, resnext50_32x4d and EfficientNet B3. [Image by Author]</figcaption></figure><p>To sum up, You can train machine learning models with mislabeled data by using:</p><ul><li><strong>The Bi-Tempered loss</strong> function and tuning its parameters <em>t1</em> and <em>t2</em> correctly.</li><li><strong>Self Distillation</strong>: Train your model and retrain it again using itself as a teacher.</li><li><strong>Ensemble learning:</strong> Ensemble the predictions of different models.</li></ul><p>If you would like to learn more details about the models training process, check <a href="https://www.kaggle.com/c/cassava-leaf-disease-classification/discussion/220621">the summary of my approach on kaggle</a>.</p><p><em>The charts were made with the app draw.io</em></p><blockquote>THE END</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf4bb353b3d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Covid-19 DNA Analysis With Biopython]]></title>
            <link>https://medium.com/swlh/covid-19-dna-analysis-with-biopython-b75e7a5ca7da?source=rss-e87127a3cbe5------2</link>
            <guid isPermaLink="false">https://medium.com/p/b75e7a5ca7da</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[covid19]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[bioinformatics]]></category>
            <category><![CDATA[biopython]]></category>
            <dc:creator><![CDATA[Amine]]></dc:creator>
            <pubDate>Thu, 07 Jan 2021 19:14:42 GMT</pubDate>
            <atom:updated>2021-05-21T15:43:07.486Z</atom:updated>
            <content:encoded><![CDATA[<h3>SARS-CoV-2 genome Analysis With Biopython</h3><h4>Simple tutorial using biopython library to analyze the SARS-CoV-2’s genome in python.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7pJ7RB9UcKH12gGBi3MBEQ.png" /><figcaption>SARS-CoV-2&#39;s genome analysis with biopython. Created with BioRender.com [Image by Author]</figcaption></figure><p>In this article, we will identify the viral proteins in the novel SARS-CoV-2 genome with biopython and do a comparative analysis with the SARS and bat coronaviruses.</p><h3>Materials and methods:</h3><ul><li>Download the genome file from the kaggle dataset: SARS-CoV-2<a href="https://www.kaggle.com/amiiiney/covid19-genbank-file"> genbank file.</a> <em>(NCBI accession number: NC_045512)</em></li><li>SARS-CoV-2 genome analysis was carried with <a href="https://biopython.org/">Biopython</a> and <a href="https://github.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer">DNA features viewer</a> libraries.</li><li><a href="https://www.ebi.ac.uk/Tools/sss/psiblast/">PSI-BLAST</a> search was used to compare our SARS-CoV-2 proteins with the SARS and Bat coronavirus proteins.</li></ul><h3>1- SARS-CoV-2 genetic information:</h3><p>Genome sequencing has increasingly become an important tool for studying disease outbreaks. The SARS-CoV-2 genome used in this study was sequenced from a sample of bronchoalveolar lavage fluid from a single patient who was a worker at the market and who was admitted to the Central Hospital of Wuhan on 26 December 2019 <a href="https://www.nature.com/articles/s41586-020-2008-3#rightslink">[1]</a>.</p><h3>2- SARS-CoV-2’s genome:</h3><p>The SARS-CoV-2 genome has 29903 nucleotides (sequence of A T C and G), to have an idea of how small it is, the human genome has more than 3 billion nucleotides. The small size of the viruses and microorganisms make them easier to study compared to the human genome.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*tArHlWWlNOpcfLq9B18SWA.jpeg" /><figcaption><strong>Figure 1</strong>. DNA is a sequence of 4 nucleotides: A T C G. Source: <a href="https://www.nature.com/scitable/topicpage/discovery-of-dna-structure-and-function-watson-397/">https://www.nature.com/scitable/topicpage/discovery-of-dna-structure-and-function-watson-397/</a></figcaption></figure><p>We start our analysis by importing the Biopython library and reading the genome file. The code below displays the SARS-CoV-2’s first 1000 nucleotides (out of 29903).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a53dd14ada395758b1e304145d7631a/href">https://medium.com/media/5a53dd14ada395758b1e304145d7631a/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*DWPPSrJ6d7IcPyy2Y5rjsA.png" /><figcaption><strong>Figure 2.</strong> SARS-CoV-2: First 1000 nucleotides (out of 29903).</figcaption></figure><blockquote>This sequence of nucleotides contains all the information encoded in the virus. Understanding this genetic information is the key to find cures and vaccines. So, the question here is: How do we extract information from this long sequence of letters?</blockquote><p>Before moving forward, let’s breakdown this long string to single characters and see the distribution of the nucleotides (A,T,C,G) over the SARS-CoV-2’s genome. The DNA sequence from NCBI is used as a starting point.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de8436d50da152f1a8fd7c9d6c11f820/href">https://medium.com/media/de8436d50da152f1a8fd7c9d6c11f820/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*4rSUJXEN7o3-H9xr1w2Yow.png" /><figcaption><strong>Figure 3.</strong> Nucleotides distribution in SARS-CoV-2’s genome. [Image by Author]</figcaption></figure><p>How do we extract information from this long sequence of letters? This process is called gene expression: Gene expression is the process by which information from a gene is used in the synthesis of a functional gene product. These products are often proteins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*XBVza7XYGZDrU3BX_k007Q.jpeg" /><figcaption><strong>Figure 4</strong>. Gene expression: DNA is transcripted to an RNA molecule, RNA is translated to amino acids, amino acids chains form proteins. Source: <a href="https://astrobiochem.wordpress.com/grade-10-biology/ch-11-gene-expression/">https://astrobiochem.wordpress.com/grade-10-biology/ch-11-gene-expression/</a></figcaption></figure><ul><li><strong>Transcription</strong>: DNA is copied out into a messenger RNA (mRNA)</li><li><strong>Translation</strong>: mRNA is translated into amino acids</li><li><strong>Amino acid folding: </strong>A sequence of 20 or more amino acids <em>(the building blocks of proteins)</em> form a protein.</li></ul><h3><strong>3- Transcription:</strong></h3><p>Transcription is the first step in gene expression. It involves copying a gene’s DNA sequence to make an RNA molecule.</p><ul><li>Basically the mRNA is a copy of our DNA. However, in RNA, a base called uracil (U) replaces thymine (T) as the complementary nucleotide to adenine (that’s the only difference, T is replaced by U).</li><li>We can transcribe our DNA sequence with biopython’s <strong><em>transcribe()</em></strong> function</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5ad955e05a4b93de245fca617121da6/href">https://medium.com/media/f5ad955e05a4b93de245fca617121da6/href</a></iframe><p>To see the difference ( T replaced by U) between both DNA and RNA, we align both sequences together:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*k3aqQCoU9RNFG1O51pm99w.png" /><figcaption><strong>Figure 5</strong>. Alignment of the first 50 nucleotides of DNA and RNA sequences</figcaption></figure><h3><strong>4- Translation</strong></h3><p>Translation is the process that takes the information passed from DNA as messenger RNA and turns it into a series of amino acids.</p><p>It is essentially a translation from one code (nucleotide A T C G sequence) to another code (amino acid sequence).</p><p>How does this translation happen? As in any language, we need a dictionary for translation. In this case, the amino acid dictionary is the table below. The nucleotides are read in groups of three “AUG GCC CAG UUA …”. Each triplet is called a codon and codes for a specific amino acid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*UMspVt2hLCaojv3vGmvVXw.jpeg" /><figcaption><strong>Figure 6</strong>. The genetic Codon Chart to pair each codon (3 nucleotides) with its corresponding amino acid. Source: <a href="https://www.3dmoleculardesigns.com/Education-Products/Genetic-Codon-Poster.htm">https://www.3dmoleculardesigns.com/Education-Products/Genetic-Codon-Poster.htm</a></figcaption></figure><p>There are 61 codons for 20 amino acids, and each of them is “read” to specify a certain amino acid out of the 20 commonly found in proteins.</p><p>Luckily, with the <strong><em>translate()</em></strong> function, biopython translates the mRNA to amino acids chains. Chains are separated with a * which is the stop codon ( UAA, UAG and UGA) <a href="https://www.khanacademy.org/science/biology/gene-expression-central-dogma/translation-polypeptides/a/translation-overview">[2]</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0cd497f5f6f9f69f93760f1fc2e13a25/href">https://medium.com/media/0cd497f5f6f9f69f93760f1fc2e13a25/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*RNxbv2tOsqPCsY5XQ956kA.png" /><figcaption><strong>Figure 7</strong>. Amino acid sequence translated from RNA.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*qfGzuFPlDImZY-ZsTA6S0w.png" /><figcaption><strong>Figure 8</strong>. Total number of amino acids in the SARS-CoV-2 genome.</figcaption></figure><ul><li>We have several chains of a total of 9967 amino acids separated with stop codons <strong>*</strong></li><li>The <strong><em>split()</em></strong> function splits the sequence at any stop codon and keeps the amino acids chains separated. This makes it easier for further analysis.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*_KmyFrhyEpnvRZ-0XQWrMw.png" /><figcaption><strong>Figure 9</strong>. Protein sequences separated from the long amino acid sequence.</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b417650b7030956556641845ec8d6748/href">https://medium.com/media/b417650b7030956556641845ec8d6748/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*fKaMFlP7s6SQjyqbzMWzxA.png" /><figcaption><strong>Table 1.</strong> SARS-CoV-2’s protein sequences with more than 50 amino acids.</figcaption></figure><p>Now that we have our protein sequences, we will use the <a href="https://www.ebi.ac.uk/Tools/sss/psiblast/">BLAST search</a>.</p><p>We will try to find the protein sequences already available in the databases that are the most similar to our protein sequences. <em>(Hint: In this case, most probably the proteins that will have the highest similarity with our </em>SARS-CoV-2<em> belong to the SARS coronavirus or Bat coronavirus).</em></p><p>An example of how BLAST works:</p><ul><li>PSI-BLAST webpage: <a href="https://www.ebi.ac.uk/Tools/sss/psiblast/">https://www.ebi.ac.uk/Tools/sss/psiblast/</a></li><li>Copy/Paste our 83 amino acid chain (from <strong><em>table 1</em></strong> above) : AQADEYELMYSFVSEETGTLIVNSVLLFLAFVVFLLVTLAILTALRLCAYCCNIVNVSLVKPSFYVYSRVKNLNSSRVPDLLV</li><li>The figure below shows the result of our 83 amino acids chain: It’s the <strong><em>Envelope small membrane protein!</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*05pWN3AlDljy9q-idyPwmg.png" /><figcaption><strong>Figure 10</strong>. Screenshot of the BLAST search results of our amino acid sequence.</figcaption></figure><h3><strong>5- Open reading frames:</strong></h3><p>An open reading frame is a portion of a DNA molecule that, when translated into amino acids, contains no stop codons. The genetic code reads DNA sequences in groups of three base pairs, which means that a double-stranded DNA molecule can read in any of six possible reading frames — three in the forward direction and three in the reverse. A long open reading frame is likely part of a gene <a href="https://www.genome.gov/genetics-glossary/Open-Reading-Frame">[3]</a>.</p><p>In order to visualize the open reading frames in our SARS-CoV-2 genome, we need to install the <a href="https://github.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer">dna_features_viewer</a> library for visualization and the <a href="https://github.com/bcbio/bcbio-nextgen">bcbio-gff</a> library for parsing.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15f25912556fe09353d016fbba6050b2/href">https://medium.com/media/15f25912556fe09353d016fbba6050b2/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K_x5jbfNd2nxaEk-PRNFIQ.png" /><figcaption><strong>Figure 11</strong>. Visualization of the ORFs in the SARS-CoV-2 genome. <strong>ORF1ab</strong> (Replicase protein), <strong>S</strong> (Spike protein), <strong>N</strong> (Nucleoprotein), <strong>E</strong> (Envelope protein) [Image by Author]</figcaption></figure><p>The figure above shows the localization of the ORFs in the SARS-CoV-2 genome. From left to right: ORF1ab (Replicase protein), S (Spike protein), E (envelope protein) and N (Nucleoprotein).</p><p>Next, we’ll use the biopython <strong><em>find_orfs_with_trans()</em></strong> function to find the amino acid sequences corresponding to the ORFs found above in the <strong><em>figure 11</em></strong> to run a BLAST search and find out more about the functionality of those viral proteins.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/204eb93788928ec18b2e97724e5d3e11/href">https://medium.com/media/204eb93788928ec18b2e97724e5d3e11/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*vRxIYdX9ejn-pcixZV0gTQ.png" /><figcaption><strong>Figure 12</strong>. ORFs. 1- Amino acid sequence, Sequence length, Strand, ORF’s position in the sequence</figcaption></figure><p>After printing out ORF sequences, we run a BLAST search as explained earlier in <strong><em>figure 10</em></strong>, and find the proteins with the highest affinity to our sequences in the BLAST database. The table below shows the results of the 6 sequences printed in <strong><em>figure 12</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*U6ZHNAivCJw1og1ci8httA.png" /><figcaption><strong>Table 2.</strong> SARS-CoV-2’s Viral proteins and their match percentage with SARS and Bat coronaviruses from BLAST search.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*tVoly1SsrWHo68vvzaGvwg.png" /><figcaption><strong>Figure 13</strong>. Amino acid sequence length of SARS-CoV-2’s ORFs. [Image by Author]</figcaption></figure><blockquote>This article is a short version of my Kaggle notebook <a href="https://www.kaggle.com/amiiiney/covid-19-proteins-identification-with-biopython/"><strong>COVID-19: Proteins identification with Biopython.</strong></a><strong> </strong>If you would like to reproduce the code, please check the notebook.</blockquote><h3>Conclusion</h3><p>We did a genome analysis with biopython and managed to find SARS-CoV-2&#39;s main viral proteins <em>(figure below)</em> : Spike protein <strong>(S)</strong>, Nucleoprotein <strong>(N)</strong>, Membrane protein <strong>(M)</strong>, Envelope protein <strong>(E)</strong> and the replicase polyprotein <strong>(1ab)</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*3OvrSYG6tyZU_-TCcc3oag.png" /><figcaption><strong>Figure 14</strong>. SARS-CoV-2-19’s viral proteins. Source: <a href="https://www.microbiologiaitalia.it/virologia/emergenza-coronavirus-una-visione-generale/">https://www.microbiologiaitalia.it/virologia/emergenza-coronavirus-una-visione-generale/</a></figcaption></figure><h3>References:</h3><p>[1] A new coronavirus associated with human respiratory disease in China <a href="https://www.nature.com/articles/s41586-020-2008-3#rightslink">https://www.nature.com/articles/s41586-020-2008-3#rightslink</a></p><p>[2] Overview of Translation: <a href="https://www.khanacademy.org/science/biology/gene-expression-central-dogma/translation-polypeptides/a/translation-overview">https://www.khanacademy.org/science/biology/gene-expression-central-dogma/translation-polypeptides/a/translation-overview</a></p><p>[3] NIH. Open Reading Frames <a href="https://www.genome.gov/genetics-glossary/Open-Reading-Frame">https://www.genome.gov/genetics-glossary/Open-Reading-Frame</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b75e7a5ca7da" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/covid-19-dna-analysis-with-biopython-b75e7a5ca7da">Covid-19 DNA Analysis With Biopython</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Drug Discovery With Neural Networks]]></title>
            <link>https://medium.com/swlh/drug-discovery-with-neural-networks-a6a68c76bb53?source=rss-e87127a3cbe5------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6a68c76bb53</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[kaggle-competition]]></category>
            <category><![CDATA[drug-discovery]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Amine]]></dc:creator>
            <pubDate>Tue, 15 Dec 2020 16:03:28 GMT</pubDate>
            <atom:updated>2021-02-09T14:23:27.022Z</atom:updated>
            <content:encoded><![CDATA[<h4>A summary of the Mechanisms of action (MoA) prediction competition on kaggle where we used deep learning algorithms to predict the MoA of new drugs.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*AYJLRDxyO6MWGVSaP6Fm2w.png" /><figcaption><strong>Figure 1. </strong>Overview (1) Human cells are treated with a drug. (2) Gene expression and cell viability measurements. (3) The data is fed to the neural network. (4) the NN predicts if a drug has a MoA or not. [Image by Author]</figcaption></figure><p>Discovering a new drug has always been a long process that takes years. With the recent advances of AI and the accumulation of research data in biological databases, the drug discovery process and the research pace are getting faster than ever. Researchers in the laboratory of innovation and science at Harvard are working on the <a href="https://clue.io/cmap">Connectivity MAP project</a> [1] with the goal of advancing drug development through improvements to the drugs MoA prediction algorithms. This challenge was launched as <a href="https://www.kaggle.com/c/lish-moa">a kaggle competition</a> [2] in order to build machine learning models to predict the MoA of unknown drugs.</p><h3>1- Dataset:</h3><p>We start by understanding the competition’s dataset: We have a dataset with gene expression and cell viability data as features and 206 MoA as targets.</p><h3>1–1 Gene expression features:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*8kbVqyBUkLis1v4CyQYbeQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*xYw7e7nnP47nQFRTK_usrg.png" /><figcaption><strong>Figure 2.</strong> Gene expression assay: The gene expression assay undergoes a series of steps starting from the selection of cell lines, drug treatment, incubation, to mRNA extraction and quantification of a subset of genes. [Image by Author]</figcaption></figure><p>The gene expression is measured for 772 genes in this dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*00VTY4WGqk9h5sePpraRhA.png" /><figcaption><strong>Figure 3.</strong> Distribution of 5 genes: g-1, g-2, g-3, g-400 and g-771 (out of 772 genes). [Image by Author]</figcaption></figure><p>Gene expression was measured with <a href="https://www.cell.com/cell/fulltext/S0092-8674(17)31309-0?_returnURL=https%3A%2F%2Flinkinghub.elsevier.com%2Fretrieve%2Fpii%2FS0092867417313090%3Fshowall%3Dtrue">L1000 assay</a>. You can learn more about this new technology in the <a href="https://clue.io/connectopedia/what_is_l1000">Connectivity map webpage</a> and the research paper: <a href="https://doi.org/10.1016/j.cell.2017.10.049">A Next Generation Connectivity Map: L1000 Platform and the First 1,000,000 Profiles,” Cell, 2017</a>.[3]</p><blockquote>For the sake of simplicity, just one experimental condition was explained. In fact, one single drug was profiled several times at different dosages (low and high) and different treatment times (24H, 48H and 72H).</blockquote><h3>1-2 Cell viability features:</h3><p>Along with the gene expression data of 772 genes, cell viability data was provided for 100 cell lines, the cell viability assay is based on <a href="https://clue.io/connectopedia/glossary#P"><strong>PRISM <em>(Profiling Relative Inhibition Simultaneously in Mixture)</em>.</strong></a>[4]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*t6y843jQfcBdOCqWhH63Qg.png" /><figcaption><strong>Figure 4.</strong> Cell viability assay:Cells are pooled and treated with the drug, incubation, dead cells count per cell line. [Image by Author]</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*kDB69vgI_l5Cm0rLEfvseQ.png" /><figcaption><strong>Figure 5.</strong> Cell viability distribution of 5 cell lines (OUT OF 100). [Image by Author]</figcaption></figure><p>The cell viability assessment is based on <a href="https://clue.io/connectopedia/glossary#P">PRISM</a> . You can learn more about this new technology in <a href="https://clue.io/connectopedia/glossary#P">the Connectivity map webpage</a> and the research paper: <a href="https://doi.org/10.1038/s43018-019-0018-6">Discovering the anticancer potential of non-oncology drugs by systematic viability profiling</a>.</p><p>Unlike the gene expression values that represent the mixture of the 100 cell lines, the cell viability values are per cell line, in other words:</p><ul><li>Gene-1 values are the average of the gene-1 expression over 100 cell lines as explained <strong>in figure 2 step 4</strong>.</li><li>Cell-1 value is the viability of the cells belonging to cell line 1 as explained <strong>in figure 4</strong>.</li></ul><p>So far, we’ve seen the gene expression features and the cell viability features after the treatment with the drugs. The only puzzle missing is the drugs mechanism of action, which is the target to predict.</p><h3>1-3 Targets: Drugs MoA</h3><p>In pharmacology, the term <strong>mechanism of action</strong> (<strong>MoA</strong>) refers to the specific biochemical interaction through which a drug substance produces its pharmacological effect.[5]</p><p>Let’s make this definition simpler, for example, the drug aspirin reduces pain and inflammation, so the MoA of aspirin:</p><ul><li>MoA’s function: <strong><em>Reducing pain and inflammation</em></strong>.</li><li>MoA’s biochemical function: Involves irreversible inhibition of the enzyme cyclooxygenase, therefore suppressing the production of prostaglandins and thromboxanes, thus, <strong><em>reducing pain and inflammation</em></strong>.</li></ul><p>This function or MoA is just one of the possible functions/MoA that the drug Aspirin can have, so one drug can have more than one mechanism of action. This makes the drugs MoA prediction a multi-label problem. We were provided 206 MoA targets per drug, labeled as (0: No MoA, 1: MoA). The table below displays 4 targets (out of 206 targets provided in this dataset).</p><ul><li><strong>sig_id:</strong> is the sample containing the mixture of 100 cell lines treated with a drug-X. (step 1)</li><li><strong>5-alpha_reductase_inhibitor, 11-beta-hsd1_inhibitor, acat_inhibitor</strong>… are the target mechanisms of action</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*zUwPptuDjBLAxrHWdnhj6g.png" /><figcaption><strong>Table 1.</strong> Example of 4 MoA targets out of 206 laballed (0: No MoA) and (1: MoA).</figcaption></figure><p>Let’s take the first row:</p><ul><li><strong>sig_id: ‘id_d00440fe6’</strong> is a mixture of 100 cell lines <em>(see step 1)</em>, it was treated with a drug X <em>(see step 2)</em>, this drug X doesn’t have the MoA ‘<strong>5-alpha_reductase_inhibitor’</strong> so it’s labeled as 0, but it has the MoA <strong>‘acat_inhibitor’</strong> so it’s labeled as 1.</li></ul><p><strong><em>Problem statement:</em></strong> 100 cell lines are treated with a drug. Gene expression and cell viability data is collected to understand the biological activity of this drug. The task is to predict the MoA of new drugs based on the gene expression and cell viability features. <em>(See figure 1)</em></p><blockquote>You can learn more about the competition’s data and the features interaction (genes, cells and drugs) in my kaggle notebook: <a href="https://www.kaggle.com/amiiiney/drugs-moa-classification-eda">Drugs MoA classification: EDA</a>.</blockquote><h3>2- Drugs MoA prediction:</h3><p>We arrive to the most exciting part of this analysis, the prediction of the mechanism of action of new drugs based on their gene expression and cell viability features.</p><p>While deep learning is dominating computer vision and natural language processing tasks, tree based algorithms (Random forrest, decision trees…) and Gradient boosting machines (XGBoost, LGBM, CatBoost…) are still the way to go with tabular data. However, this is not the case here, <strong>deep learning algorithms outperformed gradient boosting machines</strong>. Why is that? Because we have a multi-label problem with 206 targets to predict. <strong>Shallow machine learning algorithms don’t support multi-label tasks</strong>, in other words, they do not make use of the 206 targets correlation and cooccurrences to improve the accuracy of their predictions.</p><p>To have a better idea, let’s compare the performance of Ridge, LGBM, XGBoost and 3 deep learning models in this competition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*Ibc0E2PevrPbZzcvHwNsOg.png" /><figcaption><strong>Figure 6.</strong> Models performance in the MoA prediction competition on Kaggle. In red, shallow machine learning models and in green deep learning models. [Image by Author]</figcaption></figure><p>Those scores are approximate, to have a better idea how those models performed you can check out the notebooks training them on kaggle: <a href="https://www.kaggle.com/nicohrubec/206-ridges-baseline">Ridge</a>, <a href="https://www.kaggle.com/utkukubilay/drug-prediction-lgbm-model">LGBM</a>, <a href="https://www.kaggle.com/fchmiel/xgboost-baseline-multilabel-classification">XGBoost</a>, <a href="https://www.kaggle.com/demetrypascal/2heads-deep-resnets-pipeline-smoothing">ResNet</a>, <a href="https://www.kaggle.com/nicohrubec/pytorch-multilabel-neural-network">4 layers NN</a> and <a href="https://www.kaggle.com/hiramcho/moa-tabnet-with-pca-rank-gauss">TabNet</a>.</p><blockquote>The take-away from the figure above is the gap between shallow ML models and deep learning models. Deep learning models outperformed in this competition because of their ability to extract information from the 206 targets connections.</blockquote><p>The score difference between shallow machine learning models and neural networks might look small for a metric such as log-loss. I’d like to point out that neural networks extract signals from the targets correlation, that’s why they outperformed in this case, <strong>however, the correlation between the 206 targets in this dataset was very poor</strong> <em>(figure 7)</em>, most targets had 0 correlation and only 13 target-pairs had a +0.3 correlation, so there wasn’t much signal to extract, therefore, the difference in log-loss score would be much higher if the targets were more connected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*tN9KxvImxxgp13lQL9Kdwg.png" /><figcaption><strong>Figure 7.</strong> Heatmap: Correlation between the 206 targets. [Image by Author]</figcaption></figure><p>In the following section, I would like to talk about 3 deep learning architectures that performed really well on tabular data with multi-label targets.</p><h3><strong>2–1. Multi layer perceptron:</strong></h3><p>MLP or a simple feed forward neural network, <strong>the simplest neural networks architecture with 4 dense layers</strong> (first 2 layers with 2048 neurons and the last two with 1048 neurons) along with dropout, batch normalization layers and ReLu activation function, performed surprisingly well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*Og_yJo3llVjWfeIU-LxBgw.png" /><figcaption><strong>Figure 8</strong>. 4 fully connected layers neural network architecture. Each block consist of a batchNorm, dropout, dense layers and a ReLu activation function. [Image by Author]</figcaption></figure><p>The score achieved with this model was very competitive with an Adam optimizer, Reduce on plateau scheduler and a binary cross-entropy BCE With Logits Loss function that includes a sigmoid activation.</p><p>CODE: 4 layers <a href="https://github.com/Amiiney/MoA_competition/blob/main/Models/MoA_4_layers_MLP.ipynb">MLP code Github repository.</a> [9]</p><h3>2–2 TabNet:</h3><p>TabNet was introduced in 2019 by google cloud AI in the paper: <a href="https://arxiv.org/abs/1908.07442">TabNet: Attentive Interpretable Tabular Learning</a>. <strong>It’s a deep learning model for tabular data. TabNet combines the properties of neural networks and tree-based algorithms:</strong> [6]</p><ul><li>It has the power of neural networks to fit and learn complex functions with a high number of parameters.</li><li>And it has a feature selection mechanism similar to tree-based algorithms. It also uses the attention mechanism in feature selection.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_4PJEMkC-FNmLLgZiPAWVA.png" /><figcaption><strong>Figure 9.</strong> TabNet architecture. Source: <a href="https://arxiv.org/pdf/1908.07442.pdf">https://arxiv.org/pdf/1908.07442.pdf</a></figcaption></figure><p>The pytorch implementation of TabNet was done by <a href="https://github.com/dreamquark-ai">dreamquark-ai</a> in their <a href="https://github.com/dreamquark-ai/tabnet">tabnet github repository</a> and introduced to kaggle by <a href="https://www.kaggle.com/optimo">optimo</a> in his <a href="https://www.kaggle.com/optimo/selfsupervisedtabnet">TabNet Regressor notebook</a>. Tuning and understanding the hyper-parameters can lead to a very powerful model. In fact, TabNet was the strongest single model in the MoA prediction competition, outperforming all the other models.</p><p>CODE: <a href="https://github.com/Amiiney/MoA_competition/blob/main/Models/MoA_TabNet.ipynb">TabNet code in the Github repository.</a> [9]</p><h3>2–3 DeepInsight CNN:</h3><p><a href="https://www.nature.com/articles/s41598-019-47765-6">DeepInsight is a methodology to transform a non-image data to an image for convolutional neural network architecture</a> [7], this enables taking advantage of the strong pretrained CNN models like EfficientNets. This approach was published in Scientific reports of nature 2019 and introduced to kaggle by <a href="https://www.kaggle.com/markpeng/competitions">Mark Peng</a> in his <a href="https://www.kaggle.com/markpeng/deepinsight-transforming-non-image-data-to-images">image transformation tutorial</a> and <a href="https://www.kaggle.com/markpeng/deepinsight-efficientnet-b3-noisystudent">inference</a> notebooks.</p><p>Converting tabular data to image data starts by allocating the features in a feature matrix, where the location of features depends on the similarity of features, so we end up with a feature matrix with several clusters, in each cluster, similar and highly correlated features are grouped together (figure below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bjgd7VBcxROnz_9rE6Op3w.png" /><figcaption><strong>Figure 10.</strong> DeepInsight pipeline. (<strong>a</strong>) Transform a feature vector to afeature matrix. (<strong>b</strong>) Transform a feature vector to image pixels. Source: <a href="https://www.nature.com/articles/s41598-019-47765-6#Fig1">https://www.nature.com/articles/s41598-019-47765-6#Fig1</a></figcaption></figure><p><strong>The power of this methodology with gene expression data consists in the arrangement of similar genes into clusters</strong>, which makes the differences more accessible and allows for robust identification of hidden mechanisms than dealing with elements individually. Feeding those feature matrix images to CNNs helps to catch the small variation in genomic data with the power of the convolution and pooling layers.</p><p>To better understand how <a href="https://www.kaggle.com/markpeng/deepinsight-transforming-non-image-data-to-images">DeepInsight transformation</a> [8] works with our data, let’s plot the feature matrices representing the gene expression and cell viability data of 2 samples treated with 2 different targets (MoA): <strong><em>proteasome inhibitor</em></strong> and <strong><em>DNA inhibitor.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*AX6UYubRn17LwyqAGPFLWw.png" /><figcaption><strong>Figure 11.</strong> Feature matrices representing the transformed gene expression and cell viability data of 2 samples treated with 2 different drugs. [Image by Author]</figcaption></figure><p>The difference between those 2 images is clear, the sample treated with a drug having an active proteasome inhibitor has a different feature distribution and correlation than the sample treated with a drug with DNA inhibitor. This allows the pretrained convolutional neural networks to learn patterns that other models fed with tabular data can not catch.</p><p>Training a pretrained efficientNet B3 and B4 model with the deepInsight transformed images achieved competitive results, and better than that, it gave a huge boost to the final ensemble with the other neural network models since it learned new patterns only accesible in the images.</p><p>CODE: <a href="https://github.com/Amiiney/MoA_competition/blob/main/Models/MoA_DeepInsight_B4.ipynb">Image transformation + efficientNet B4 code in the github repo</a>. [9]</p><h3>Conclusion:</h3><p>Along with the models mentioned in this article, other models performed well in this competition with tabular data and multi-label targets such as LSTM and GRU that are sequential models. The advances of AI are getting us to the point of solving a tabular data problem with an ensemble of CNNs and RNNs.</p><h3><strong>References:</strong></h3><ul><li>1- <strong>Connectivity map project:</strong> <a href="https://clue.io/cmap">https://clue.io/cmap</a></li><li>2- <strong>MoA prediction competition:</strong> <a href="https://www.kaggle.com/c/lish-moa">https://www.kaggle.com/c/lish-moa</a></li><li>3- <strong>L1000 assay</strong>: ubramanian et al. “A Next Generation Connectivity Map: L1000 Platform and the First 1,000,000 Profiles,” Cell, 2017, <a href="https://doi.org/10.1016/j.cell.2017.10.049">https://doi.org/10.1016/j.cell.2017.10.049</a></li><li>4- <strong>PRISM: </strong>Corsello et al. “Discovering the anticancer potential of non-oncology drugs by systematic viability profiling,” Nature Cancer, 2020, <a href="https://doi.org/10.1038/s43018-019-0018-6">https://doi.org/10.1038/s43018-019-0018-6</a></li><li>5- <strong>MoA definition:</strong> <a href="https://en.wikipedia.org/wiki/Mechanism_of_action">https://en.wikipedia.org/wiki/Mechanism_of_action</a></li><li>6- <strong>TabNet:</strong> <a href="https://arxiv.org/abs/1908.07442">https://arxiv.org/abs/1908.07442</a></li><li>7- <strong>DeepInsight: </strong><a href="https://www.nature.com/articles/s41598-019-47765-6">https://www.nature.com/articles/s41598-019-47765-6</a></li><li>8- <strong>DeepInsight transformation tutorial:</strong> <a href="https://www.kaggle.com/markpeng/deepinsight-transforming-non-image-data-to-images">https://www.kaggle.com/markpeng/deepinsight-transforming-non-image-data-to-images</a></li><li>9- <strong>MoA github repository: </strong><a href="https://github.com/Amiiney/MoA_competition">https://github.com/Amiiney/MoA_competition</a></li></ul><h4>The diagrams, graphs and illustrations were made by:</h4><ul><li><strong>Diagrams</strong>: <a href="https://biorender.com/">https://draw.io/</a></li><li><strong>Biological illustrations:</strong> <a href="https://biorender.com/">https://biorender.com/</a></li><li><strong>Graphs:</strong> Made with python’s matplotlib library.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6a68c76bb53" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/drug-discovery-with-neural-networks-a6a68c76bb53">Drug Discovery With Neural Networks</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>