<?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 Cathy Qian on Medium]]></title>
        <description><![CDATA[Stories by Cathy Qian on Medium]]></description>
        <link>https://medium.com/@zhaoxiaq?source=rss-1ba5748fd80d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Cathy Qian on Medium</title>
            <link>https://medium.com/@zhaoxiaq?source=rss-1ba5748fd80d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 17:00:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zhaoxiaq/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[Conquer the Coding Interview In Python Effectively — From Zero to Mastery]]></title>
            <link>https://medium.com/@zhaoxiaq/conquer-the-coding-interview-in-python-effectively-from-zero-to-mastery-4d75fa7c459?source=rss-1ba5748fd80d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d75fa7c459</guid>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[coding-interviews]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Cathy Qian]]></dc:creator>
            <pubDate>Tue, 08 Aug 2023 05:09:12 GMT</pubDate>
            <atom:updated>2023-08-08T05:09:12.182Z</atom:updated>
            <content:encoded><![CDATA[<h3>Conquer the Coding Interview In Python Effectively — From Zero to Mastery</h3><p>I recently concluded a three-month job search journey following my Twitter exit and have decided to embark on a new journey at the Pinterest Ads Monetization team. To bring closure to this phase, I have meticulously compiled my interview notes into a 117-page book aiming to help engineers to speed up their coding interview preparation process.</p><p>Similar to many fellow software engineers, I find technical interviews in the high-tech industry time-consuming. We have to spend weeks if not months honing our proficiency in data structures and algorithms before even engaging in the initial technical screen. Personally, I have often pondered the potential of redirecting such effort towards other meaningful pursuits. While there is no shortage of instructional materials available, ranging from extensive manuals to fragmented tutorials, I have often found them overly detailed or scattered, ultimately failing to optimize my time efficiency. With years of industry experience under my belt, I have developed a robust grasp of data structures and algorithms. <strong>What truly benefits me, however, are succinct and practical resources that facilitate a rapid review of essential syntax, data structures, and algorithms.</strong> This enables me to be readily prepared for interviews without undue delay. Regrettably, the existing materials have not yet provided a resource that fulfills my exact requirements. Therefore, I decide to craft my own interview preparation book.</p><p>This book will be very helpful for people who</p><ul><li>are having a difficult time passing coding interviews in the high-tech industry</li><li>or are spending months preparing for coding interviews and desire to accelerate your preparation process</li><li>or simply want to refresh his or her memory on Python syntaxes and algorithms so that you can rock the coding interview in days</li></ul><p>Feel free to check it out <a href="https://leanpub.com/conquerthecodinginterviewefficientlyinpythonfromzerotomastery">here</a>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hQTx4X6RdX9tT1oOMyth4g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d75fa7c459" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Predicting Molecular Activity Using Deep Learning in TensorFlow]]></title>
            <link>https://medium.com/data-science/predicting-molecular-activity-using-deep-learning-in-tensorflow-f55b6f8457f9?source=rss-1ba5748fd80d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f55b6f8457f9</guid>
            <category><![CDATA[biochemistry]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Cathy Qian]]></dc:creator>
            <pubDate>Sat, 30 Jun 2018 16:45:56 GMT</pubDate>
            <atom:updated>2018-07-03T13:08:52.715Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m8tMh2KyRFjliYOqJg3f-A.png" /></figure><p>Having a rich background in the STEM field, I have seen a boom in using machine learning to solve challenging scientific problems in the last couple of years. However, it is relatively hard to have profound knowledge in both the STEM field and machine learning. For example, if you are a materials scientists or biochemists, you may spend most of your day thinking about how to design experiments and how to collect data. You hear everyone talking about machine learning nowadays and feel it is really cool. However, you don’t know how to dive into this rising field with your science background. Here comes this article. It will provide a comprehensive demo to solve the <a href="https://www.kaggle.com/c/MerckActivity">Merck Molecular Activity Kaggle Challenge</a> using deep learning with the TensorFlow library.</p><p><strong>1.</strong> <strong>Problem Description</strong></p><p>Predicting the activity of a novel compound is a real challenge encountered in pharmaceutical companies when developing new drugs. During the drug discovery process, it is standard practice to scan a large library of compounds to test their biological activity towards both the intended target molecule as well as peripheral off-target molecules. It is desirable for a compound to be highly specific in order to have high efficacy and minimize side effects — that is, it should be highly active against the target molecule while showing low or no activity towards off-target molecules. This process can be very time-consuming and expensive. It is therefore desirable to quantitatively predict such biological activity between compounds and both target and off-target molecules. Such predictions can help prioritize experiments and reduce the experimental work that needs to be performed. Indeed, such predictions are called Quantitative structure−activity relationships (QSAR)<strong> </strong>and are very commonly used in the pharmaceutical industry.</p><p>The QSAR method has the following characteristics:</p><p>1) The data set in an pharmaceutical environment usually involves a large library of compounds. For example, each target is tested against over 20,000 compounds in this Merck data challenge.</p><p>2) Each compound is usually represented by a list of features or fingerprint descriptors. These fingerprints typically describe the content, chemistry, and molecular topology of the molecule and are encoded by a feature vector. For example, content and chemistry can include descriptors for the number of carbon and nitrogen atoms, hydrogen-bonding donors and acceptors, charges, polar and nonpolar atoms, and functional groups (ketone, carboxylic acid, etc). The topology includes which atoms are bonded to which other atoms within a specific radius (i.e. a subgraph of the molecular graph). The Merck challenge as described on the Kaggle does not give the specific fingerprints used, only the feature vectors as raw data.</p><p>3) Each set of compounds may involve a total number of thousands of fingerprint descriptors. Therefore, the vectors describing each compound are sparse and only a small proportion of them are nonzero.</p><p>4) These descriptors are not all independent. Depending on the structure of the compound, strong correlations may exist between different descriptors.</p><p><strong>2.</strong> <strong>Objective &amp; Data</strong></p><p>The objective of this Merck data challenge is to identify the best statistical techniques for predicting biological activities of compounds against specific molecules given the numerical descriptors generated from the chemical structures of these compounds.</p><p>The data provided by Merck is based on 15 target molecules and over 10,000 compounds for each target. For each target molecule, each row of the data corresponds to a compound and contains descriptors derived from that compound’s chemical structure. Activity between the target molecule and each compound is provided in the training data and is the target for prediction in the test data.</p><p><strong>3.</strong> <strong>Evaluation Metric</strong></p><p>Predictions for activity will be evaluated using the correlation coefficient R^2, averaged over the 15 data sets. For each data set,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*dwwbLcYybM_-tbrjoiZavA.jpeg" /></figure><p>where <em>x</em> is the known activity, <em>x¯</em> is the mean of the known activity, <em>y</em> is the predicted activity, <em>y¯</em> is the mean of the predicted activity, and <em>Ns</em> is the number of molecules in data set s.</p><p><strong>4.</strong> <strong>Approaches and Solutions</strong></p><p>Given that the target variable activity is continuous and each dataset contains tens of thousands of entries, this is a regression problem and I will build a neural network(NN) using the TensorFlow library in Python to make predictions. The cost function is defined as mean squared error or MSE in this work.</p><p>Below is a summary of factors considered in this work:</p><p><strong>4.1 One model for each target molecule or for all target molecules</strong></p><p>Theoretically, merging the data for all 15 molecules and training a universal model will be ideal since a much larger training data will be used and the model may perform better. However, in this particular problem, these 15 target molecules can be very different from each other in both structures and activities. Thus, it is not immediately intuitive how data for one target molecule may be useful for training model on the other molecule. Given the limit of computational power, one model for each target molecule may be preferred. Alternatively, we can train one good model and apply it over all 15 datasets. <strong><em>As a showcase, only the model for the first target molecule is trained and optimized in this work.</em></strong></p><p><strong>4.2 Data preprocessing</strong></p><p><strong>4.2.1 Target</strong></p><p>The training data has 37k entries among which over 20k have the same activity value 4.30 and the rest between 4.30 and 8.5 (Figure 1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*JelnreRXXL66uaFExkykUQ.png" /><figcaption><strong>Figure 1. Histogram of activity values in the training data for molecule 1.</strong></figcaption></figure><p>This comes from setting a threshold during the data collection process. For example, any data below 4.30 is not collected or mapped to 4.30 due to experimental limitation. Thus, a majority of the target data is truncated and the NN may have problems where it predicts the outputs to be one single value. The following preprocessing steps are tried:</p><p>1) no preprocessing</p><p>2) remove all entries with a target value of 4.30</p><p>3) randomly remove 90% of all entries with a target value of 4.30</p><p>Among them, 1) appeared to give the highest and most consistent R^2 value, probably related to having the largest amount of input data fed into the NN (Figure 2). Thus, no preprocessing of the target y is done. However, the optimizer clearly has a difficult time with the dataset, which I will touch upon in section 4.3.5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*jNGmAg9XJ1J4v1NrXV7dOg.png" /><figcaption><strong>Figure 2. R^2 value for 8 runs of the same neural network with the full training dataset or partial dataset with all entries with a target value of 4.30 removed.</strong></figcaption></figure><p><strong>4.2.2 Number of features</strong></p><p>There are 9491 features for each entry and most feature vectors have a large number of zeros. The following preprocessing steps are tried in order to remove trivial information and speed up the training process of the model:</p><p>1) no preprocessing</p><p>2) filter out features with a variance below a threshold. For example, a threshold of 5e-4 will remove 3.31% of the features.</p><p>3) use principal dimensionality reduction (PCA) to reduce the dimension(for example, to 6000 instead of 9491 features)</p><p>It turned out that both 1) and 2) gives comparable R^2 while 3) gives lower R^2 values. Thus in the following results, the features are not preprocessed.</p><p><strong>4.2.3 Descriptors</strong></p><p>All descriptors are non-negative integers. Options for the descriptor transformations are:</p><p>1) no transformation</p><p>2) logarithmic transformation, i.e. y = log(x + 1)</p><p>3) binary transformation, i.e. y = 1 if x &gt; 0, otherwise y = 0.</p><p>Figure 3 shows how the cost function change with number of epochs for the above three different processing steps. It is obvious that binary or logarithmic transformation of the descriptors x will decrease the cost function to below 0.2 and less oscillation with increasing epoch numbers. Worth to mention is that cost function above 0.2 usually means R^2 is close to 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*S3pgBf2yTfJ8IKKx9ZXngg.png" /><figcaption><strong>Figure 3. Change of cost function with increasing epoch number for three different x preprocessing.</strong></figcaption></figure><p>Comparable R^2 values (around 0.6) are achieved using logarithmic and binary transformation of descriptors x. So logarithmic transformation of descriptor x is used for the rest of the training process.</p><p><strong>4.3</strong> <strong>Parameters of the neural network</strong></p><p><strong>4.3.1</strong> <strong>Architecture of neural network</strong></p><p>Every NN has at minimum three layers: input, hidden and output. For input there is exactly one input layer, and its number of neurons is uniquely determined by the shape of the training set. For the regression in this problem, NN has only one output layer with exactly one node and linear function as its activation function.</p><p>Determining the number of hidden layers is critical. While one hidden layer is good for a majority of problems, NN with one hidden layer gives R^2 value of around 0 or meaningless value NAN because all predicted target values are exactly the same. Increasing the number of hidden layers to two without optimizing hyperparameters can give R^2 of around 0.56. Therefore, NN with two hidden layers are preferred.</p><p>As to the number of neurons in each hidden layer, the most common rules-of-thumb is ‘the optimal size of the hidden layer is usually between the size of the input and size of the output layers’. Figure 4 compared the R^2 value for 4 different NN with different number of nodes in the hidden layers over multiple training trials. The NN with 5 and 2 nodes in the first and second hidden layer respectively has similar maximum R^2 values (~ 0.6) as the other three NN with more nodes, but it has three trials with much lower R^2 which indicates the instability of NN with small number of nodes. The NN with 50 and 25 nodes in the first and second hidden layer shows the most consistent result among the 8 trials, with an average R^2 of 0.568 and a standard deviation of 0.027. The largest NN with 100 and 50 nodes in the first and second hidden layer also shows inconsistency among the 8 trials, with 1 meaningless R^2 and 1 R^2 close to 0. This is probably because 300 epochs is not enough for the larger NN to reach its global minimum consistently. Indeed, the bigger the NN, the more epochs it needs to run in order to get consistently decent R^2. Ideally, we want to run a NN as long as the computational power allows until we can see the optimizer converge on a solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*1ruWyL1hQucjhU4Trn1W0Q.png" /><figcaption><strong>Figure 4. R^2 value in different trials for NN with 2 hidden layers and different node numbers ((5, 2), (10, 5), (50, 25), (100, 50) for the first and second hidden layer respectively.) 300 epochs are run for each NN.</strong></figcaption></figure><p><strong>4.3.2</strong> <strong>Activation function</strong></p><p>The practical role of activation functions is to enable NN to model complex, nonlinear functions. Without nonlinear activation functions, a NN will be equal to a linear function. In this particular problem, ReLu and Sigmoid are tried as activation functions. ReLu performs better than Sigmoid and used in all hidden layers. The cost function indeed doesn’t converge when using Sigmoid activation function. This may be because the Sigmoid activation function confines all output between 0 and 1 and thus dampens the training ability of the NN for this particular problem.</p><p>Linear activation is used for the output layer, which is a common practice for training NN for regression problems.</p><p><strong>4.3.3 Learning rate</strong></p><p>The output of the NN is very sensitive to the initialized learning rate of the gradient descent. I started with a learning rate of 0.05 and noticed that the cost function either diverge or quickly go beyond the maximum floating point number, giving NaN. Decreasing the learning rate will decrease the cost function, however, the cost function are easily trapped in local minimum (24.085, 22.220, 14.683, for instance). Only when the learning rate decreased to 0.001, I start to see consistent output of cost and R^2 value over 0.1. Thus, the learning rate is kept at 0.001.</p><p><strong>4.3.4 Weight and biases</strong></p><p>Given that the cost function easily goes to local minima, it’s also important to start with optimized weight and biases. Our optimized weights and biases are random values from a truncated normal distribution with a mean of 0 and standard deviation of 1. Values who is outside of [-2, 2] are dropped and re-picked — this step is very important for getting consistent results.</p><p><strong>4.3.5 Optimizer</strong></p><p>The Adam optimizer turned out to be the best optimizer. Stochastic gradient descent was initially used, but most times the cost function will be trapped in local minima (0.45 for instance). Decreasing the learning rate and adding momentum did not help much. After switching the optimizer to Adam (adaptive moment estimation) optimizer, the cost function started to decrease to as much as less than 1 and converge. Adam optimizer computes adaptive learning rates for each parameter and keeps an exponentially decaying average of past gradient. It is usually the go-to optimizer for NN with input data as sparse matrix.</p><p>However, the cost function (MSE) can still be trapped in local minimum. For example, Figure 5 shows the change of cost function and R^2 value along with increasing epoch number for a NN with two hidden layers with 1000 and 500 nodes respectively. At epoch 865, the cost does a small hop from below 0.2 to above 0.4 into a sharp local minima that it never recovers from. The R^2 is really bad afterwards, while it was much better before epoch 865. The cost function landscape is likely to encompass a lot of very sharp local minima, since we often see training trials get trapped at around the 0.4–0.5 MSE with bad R^2 (see Figure 4 for some examples). This hopping phenomenon happens randomly in all simulations and is hard to control. Thus, for each optimized model, I usually run it multiple times in order to get consistent results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*xcsAhC990RIsgYZI1Gyi5g.png" /><figcaption><strong>Figure 5. Change of cost function and R^2 value with epoch number. The NN has 2 hidden layers with 1000 and 500 nodes respectively. All other parameters of the NN is optimized as shown in this report.</strong></figcaption></figure><p><strong>4.3.6 Dropout</strong></p><p>Dropout is a common strategy used for preventing overfitting in a NN. Optimized results are achieved with 25% neural nodes dropped out randomly in the hidden layer and no dropout in the output layer.</p><h4><strong>5.</strong> <strong>Summary</strong></h4><p>In conclusion, the optimized NN that gives the highest R^2 value has the following characters:</p><ul><li>All training data and all descriptors are used without any filtering process.</li><li>Logarithmic transformation of descriptors x and no preprocessing of target y.</li><li>The NN has two hidden layers. The first and second hidden layers have 50 and 25 neurons respectively.</li><li>ReLu is used as the activation function for all hidden layers. Linear activation function is used for the output layer.</li><li>The learning rate is kept at 0.001.</li><li>Weights and biases are random values from a truncated normal distribution with a mean of 0 and standard deviation of 1. Values who is outside of [-2, 2] are dropped and re-picked.</li><li>Adam optimizer is used.</li><li>A dropout rate of 25% is used for all hidden layers and no dropout is used in the output layer.</li><li>Batch size is 300 and epoch number is 900.</li></ul><p>The highest R^2 value on the test data (which is 20% split from the training data) is 0.568 +/- 0.027. The Kaggle leadership board shows a top average R^2 score of 0.494 for all 15 molecules. Compared to that result, the R^2 value from the NN is decent and satisfactory.</p><p>Please see this <a href="https://github.com/CathyQian/Predicting-Merck-Molecular-Activity">GitHub</a> repository for all code and supplementary information. Feel free to leave comments or contact me if you have any questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f55b6f8457f9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/predicting-molecular-activity-using-deep-learning-in-tensorflow-f55b6f8457f9">Predicting Molecular Activity Using Deep Learning in TensorFlow</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>