<?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 Marek Bielik on Medium]]></title>
        <description><![CDATA[Stories by Marek Bielik on Medium]]></description>
        <link>https://medium.com/@marek_52731?source=rss-1b5698dd4693------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*t4acu-APFW5wkBgaaC_bGA.jpeg</url>
            <title>Stories by Marek Bielik on Medium</title>
            <link>https://medium.com/@marek_52731?source=rss-1b5698dd4693------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 23:11:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@marek_52731/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[Malware detection and artificial neural networks]]></title>
            <link>https://medium.com/@marek_52731/malware-detection-ann-637c328dca18?source=rss-1b5698dd4693------2</link>
            <guid isPermaLink="false">https://medium.com/p/637c328dca18</guid>
            <category><![CDATA[metrics]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[convolutional-network]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Marek Bielik]]></dc:creator>
            <pubDate>Fri, 29 Nov 2019 22:45:34 GMT</pubDate>
            <atom:updated>2019-12-05T20:13:22.703Z</atom:updated>
            <content:encoded><![CDATA[<p>Artificial neural networks such as MLP (MultiLayer Perceptron) and CNN<br>(Convolutional Neural Networks) have been successfully used to statically<br>classify malware. This article should help beginners in the realm of deep learning to apply these models in practice as we will walk through a task of static malware classification. We will assume that the reader has just explored what MLP and CNN are but haven’t used them yet. We will also not focus on the code but rather guide the reader through the overall process and hopefully provide intuition that will come in handy in the future. We will also explain various metrics that are useful in binary classification. You are welcome to explore the code at <a href="https://gitlab.fit.cvut.cz/bielima2/mvi-sp">https://gitlab.fit.cvut.cz/bielima2/mvi-sp</a> as well though.</p><h3>Data description</h3><p>The <a href="https://github.com/endgameinc/ember">EMBER</a> data set contains features extracted from executable files in the PE (Portable Executable) format. Each file is abstracted into a JSON object which can be subsequently transformed into a feature vector containing 2351 dimensions. Besides the JSON data, the authors of the data set also provided methods for transforming it into the feature vectors. These methods implement embedding techniques, such as the hashing trick where appropriate. We will focus on EMBER2018 which contains:</p><ul><li>training data:</li><li>— 200 000 unlabelled samples</li><li>— 300 000 malicious samples</li><li>— 300 000 benign samples</li><li>test data:</li><li>— 100 000 malicious samples</li><li>— 100 000 benign samples</li></ul><h3>Data Preprocessing</h3><p>At the very beginning, the unlabelled samples were cleared away. The first obstacle that emerged during the process of building our classifiers was that it was not possible to train it on the raw 2351 dimensional vectors provided by the data set. The accuracy even on the training data was always no better than the accuracy of a random classifier regardless of the architecture of the network. The reason was that the variance of the data was too high, namely 8.8196516×10¹⁴. On the other hand, the accuracy of the gradient boosted decision tree provided by the authors of the data set was 93.61 %. We decided to standardize the data by calculating the standard score. Since the resulting data contained NaN (Not a Number) values, the accuracy was still no better than random. After setting the NaN values to zero, the neural networks started learning.</p><p>The next step was to examine the data by performing a PCA (Principal Component Analysis). The PCA revealed that the first dimension of the new space contains approximately 3.5 % of variance and that the first 1024 components contain approximately 90 % of variance. Since training with 1024 dimensional vectors is much faster than training with the original vectors, and the loss of information was acceptable, we decided to utilize this reduction.</p><h3>Experiments</h3><p>The neural networks in the experiments are implemented by leveraging the <a href="https://keras.io/">Keras</a> library. We have also employed a hyper-parameter optimization technique called random search which is implemented in the <a href="https://keras-team.github.io/keras-tuner/">Keras Tuner</a> library.</p><p>Besides the accuracy metric for model evaluation, we will also consider the precision and recall metrics. These metrics use the notion of true and false positives and negatives. In malware detection, a false positive means that the file is considered malicious even though it is actually harmless. On the other hand, a false negative means that a malicious activity has not been detected.</p><p>In our case, precision describes the cost of false positives (when our model falsely thinks that a benign file is malicious) and is defined by the following formula:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xmr42ovOJqrzPFWgIqxzxA.png" /></figure><p>Recall is defined in a similar fashion:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*v5cX-eMYpAxbB6XD43oJbQ.png" /></figure><p>Note that the denominator in the definition of recall is in fact the sum of all actually positive samples. Recall describes how good our model is at capturing files that are truly malicious and as such, it can be seen as the probability of detection.</p><p>We will also use the terms FPR (False Positive Rate) and TPR (True Positive Rate). FPR is defined by the following formula:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*4oI2BUgyGhXE1-UnXlzpdw.png" /></figure><p>Notice again that the denominator is the sum of all truly negative samples. TPR is defined in the same way as recall and is therefore just a synonym. We will utilize ROC (Receiver Operating Characteristic) curves that show the relation between FPR and TPR. The goal for a binary classifier is to have high TPR at low FPR. We can therefore compare our models based on this metric. Another metric is the AUC (Area Under Curve). This metric integrates the area under the ROC curve. An ideal classifier would have the AUC equal to 1.</p><h4>Multilayer Perceptron Networks</h4><p>Since machine learning utilizing neural networks is an empirical realm, we start by experimenting with the network architecture and its hyper-parameters. In order to estimate these parameters, the model was run multiple times on a reduced data set for 5 epochs.</p><p>The MLP model was run for 6000 times by the random search routine with various hyper-parameters and the best 10 runs had the following common properties: dropout was set to zero, the activation function was ReLU (Rectified Linear Unit) and the optimizing method was Adam (Adaptive Moment Estimation). The layer width of the best performing models was mostly between 512 and 64 neurons. Larger or smaller layers were not preferred. These results provided with an elementary insight into suitable models and the preceding hyper-parameters were set for all the subsequent models.</p><p>The next step was to estimate the most appropriate depth of the network. The model was run again for 3000 times and the best performing network had 4 layers with 512 neurons, 2 layers with 128 neurons and one layer with 64 neurons. This network was then retrained on the full data set for 50 epochs as further training did not provide any performance improvement.</p><p>The last layer always had one neuron with a sigmoid function as the activation function. The loss function was the cross-entropy measure. The learning rate was chosen automatically by the Keras library.</p><h4>Convolutional Neural Networks</h4><p>As mentioned in the introduction, CNN have also been used to statically analyze malware. We have tried to build a 1D CNN in a similar fashion as described in the previous section. This time; however, the search for hyper-parameters was much slower due to higher computational demands — the model was much slower to train and the hyper-parameter search space was much larger. The model was run for 3000 times and the best performing network had the following properties: there were three convolutional layers with 16 kernels, the size of each kernel was 32. There were also four dense MLP layers with sizes 512, 256, 128 and 64. The stride parameter of the convolutional layers was set manually to two in order to speed up the training. The rest of the hyper-parameters was kept the same as in the MLP model.</p><p>Researchers have also tried to detect malicious software by transforming it to images and then apply 2D CNN. We have also tried such an approach by transforming the feature vectors to matrices (with 32 rows and columns since the feature vectors have 1024 dimensions) and then we naively tried to adapt and retrain a pre-built CNN called VGG16. The motivation for this was to find out whether a network with an architecture that works well for recognizing general images could have good performance in our domain as well. Originally, the network had 1000 output neurons. We added one more neuron on top of this layer in order to transform the network into a binary classifier. The activation function of the neuron was a sigmoid function. The optimizing method and loss function were also chosen the same as in the MLP model. The convolutional networks were also trained on the full data set for 50 epochs.</p><h3>Results</h3><p>The following table shows the metrics comparison of trained models on the test data. The MLP model has the highest accuracy, and it also outperforms the baseline GBDT provided by the ember library. It is also worth noting that the MLP model has much plainer architecture than the VGG16 network for example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*loMWRAaXM4qalsvTGW_J3g.png" /></figure><p>The following two figures show the ROC curves for our trained models. The MLP model has the best ROC up to around 15 % FPR where it is surpassed by the GBDT model. The adapted VGG16 has actually the poorest performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*5WfIZ0K-hJE22o9TZishHg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*kbGY3EtmkOr8kx_AMZM8BQ.png" /></figure><p>The next figure depicts the classification distribution of the MLP model. We can see that for most samples, the model gives a confident correct answer. However, there is also a considerable amount of samples for which the model gives the wrong answer with certainty as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*ZXnzm5_dxD5xVweOyYTnKg.png" /></figure><p>The next two figures show that the convolutional networks have similar behavior to the MLP model as regards the classification distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*LKHHUcltOKtPkdQ7DjSS1A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*0zYtBfaxLevg3XE4Ht6fcA.png" /></figure><p>The next figure shows the classification distribution for the MLP model, which classified the raw data from the data set. We can see that the model classified most samples as positive (the output value for most samples was 0.5). This is the reason why this model has the highest recall in the table above. However, the precision is very low and since the data set contains an equal amount of benign and malicious samples, the accuracy is close to the accuracy of a random classifier, which is exactly 50 %.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*CcFZ8UdSbYCG8KL00nKdwQ.png" /></figure><h3>Dimensionality reduction experiments</h3><p>Besides PCA, a VAE (Variational AutoEncoder) can also be used to reduce the dimensionality of the data. We have experimentally built and trained a VAE that reduces our data into three dimensions. The architecture and hyper-parameters of the encoder and decoder of the VAE were chosen so that they match the best performing MLP model. The following image shows the resulting three-dimensional data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cmXNCM6dZ8y_ctWAKkM9Hw.png" /></figure><p>We see that all the samples are gathered in a single dense cloud, which means that the classification is not a straightforward task. For comparison, the last image shows the same data after a reduction into three dimensions by PCA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kqB9I8gMAntPrJECn8avsA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=637c328dca18" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>