{"id":2820,"date":"2026-11-28T12:00:00","date_gmt":"2026-11-28T12:00:00","guid":{"rendered":"https:\/\/sites.wp.odu.edu\/locky\/?p=2820"},"modified":"2026-10-26T20:49:31","modified_gmt":"2026-10-26T20:49:31","slug":"transfer-learning-for-lstm-anomaly-detection","status":"publish","type":"post","link":"https:\/\/sites.wp.odu.edu\/locky\/2026\/11\/28\/transfer-learning-for-lstm-anomaly-detection\/","title":{"rendered":"Transfer Learning for LSTM Anomaly Detection"},"content":{"rendered":"\n<p>Transfer learning is supposed to save training time. In my experiment, it took 5.7 times longer and gained nothing.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The setup<\/h3>\n\n\n\n<p>No pre-trained model exists for this kind of security data, so I built one. I split NSL-KDD network traffic by protocol. An LSTM learned from about 14,000 sequences of TCP connections. Then I adapted it to UDP and ICMP traffic using only 1,200 labeled sequences.<\/p>\n\n\n\n<p>The adaptation ran in two phases. First, I froze the pre-trained layers and trained only a new output layer. Then I unfroze everything and continued at a learning rate ten times lower.<\/p>\n\n\n\n<p>For a fair comparison, I trained an identical model from scratch on the same 1,200 sequences.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The result<\/h3>\n\n\n\n<p>Accuracy was effectively tied: 0.9508 for transfer, 0.9465 from scratch. That gap is three sequences out of 691. Rerunning the scratch model with different random seeds moved it by the same three.<\/p>\n\n\n\n<p>The difference was cost. The scratch model finished in 25 epochs and 4.4 seconds. The transfer model needed 183 epochs and 24.9 seconds.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why it didn\u2019t pay off<\/h3>\n\n\n\n<p>The two domains only looked similar. They shared the same columns, but only two of the ten target services appeared in the source data. The connection flag field had eleven values in TCP traffic and one in UDP\/ICMP.<\/p>\n\n\n\n<p>The pre-trained model had learned TCP session structure. Fine-tuning had to largely overwrite that before it became useful. The target task was also easy, which left little room for prior knowledge to help.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The takeaway<\/h3>\n\n\n\n<p>Transfer learning works when the domains are close. Measuring that distance first would have predicted this result.<\/p>\n\n\n\n<p>The full report is on my <a href=\"https:\/\/sites.wp.odu.edu\/locky\/coursework\/cybersecurity-applications\/cyse-420-applied-ml-in-cybersecurity\/\">CYSE 420 course page<\/a>.<\/p>\n\n\n<a href=\"https:\/\/sites.wp.odu.edu\/locky\/wp-content\/uploads\/sites\/38189\/2026\/10\/CYSE420_Assignment07_Report.pdf\" class=\"pdfemb-viewer\" style=\"\" data-width=\"max\" data-height=\"max\"  data-toolbar=\"both\" data-toolbar-fixed=\"on\">CYSE420_Assignment07_Report<br\/><\/a>\n<p class=\"wp-block-pdfemb-pdf-embedder-viewer\"><\/p>\n\n\n\n<ul class=\"wp-block-social-links has-normal-icon-size has-visible-labels has-icon-color has-icon-background-color is-style-default is-horizontal is-content-justification-center is-layout-flex wp-container-core-social-links-layout-1 wp-block-social-links-is-layout-flex\"><li style=\"color: #ffffff; background-color: #cf2e2e; \" class=\"wp-social-link wp-social-link-chain has-white-color wp-block-social-link\"><a rel=\"https:\/\/www.credly.com\/users\/carl-lochstampfor-jr noopener nofollow\" target=\"_blank\" href=\"http:\/\/sites.wp.odu.edu\/locky\/wp-content\/uploads\/sites\/38189\/2026\/10\/CYSE420_Assignment07_Report.pdf\" class=\"wp-block-social-link-anchor\"><svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M15.6,7.2H14v1.5h1.6c2,0,3.7,1.7,3.7,3.7s-1.7,3.7-3.7,3.7H14v1.5h1.6c2.8,0,5.2-2.3,5.2-5.2,0-2.9-2.3-5.2-5.2-5.2zM4.7,12.4c0-2,1.7-3.7,3.7-3.7H10V7.2H8.4c-2.9,0-5.2,2.3-5.2,5.2,0,2.9,2.3,5.2,5.2,5.2H10v-1.5H8.4c-2,0-3.7-1.7-3.7-3.7zm4.6.9h5.3v-1.5H9.3v1.5z\"><\/path><\/svg><span class=\"wp-block-social-link-label\">Full Screen or Download<\/span><\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I pre-trained an LSTM on TCP traffic and fine-tuned it on UDP\/ICMP data. It matched a model trained from scratch, at 5.7 times the training time.<\/p>\n","protected":false},"author":30379,"featured_media":2821,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"image","meta":{"footnotes":"","wds_primary_category":60},"categories":[165,60],"tags":[295,274,296],"_links":{"self":[{"href":"https:\/\/sites.wp.odu.edu\/locky\/wp-json\/wp\/v2\/posts\/2820"}],"collection":[{"href":"https:\/\/sites.wp.odu.edu\/locky\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.wp.odu.edu\/locky\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.wp.odu.edu\/locky\/wp-json\/wp\/v2\/users\/30379"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.wp.odu.edu\/locky\/wp-json\/wp\/v2\/comments?post=2820"}],"version-history":[{"count":1,"href":"https:\/\/sites.wp.odu.edu\/locky\/wp-json\/wp\/v2\/posts\/2820\/revisions"}],"predecessor-version":[{"id":2822,"href":"https:\/\/sites.wp.odu.edu\/locky\/wp-json\/wp\/v2\/posts\/2820\/revisions\/2822"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sites.wp.odu.edu\/locky\/wp-json\/wp\/v2\/media\/2821"}],"wp:attachment":[{"href":"https:\/\/sites.wp.odu.edu\/locky\/wp-json\/wp\/v2\/media?parent=2820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.wp.odu.edu\/locky\/wp-json\/wp\/v2\/categories?post=2820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.wp.odu.edu\/locky\/wp-json\/wp\/v2\/tags?post=2820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}