Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Machine Learning for Cybersecurity

You're reading from   Hands-On Machine Learning for Cybersecurity Safeguard your system by making your machines intelligent using the Python ecosystem

Arrow left icon
Product type Paperback
Published in Dec 2018
Publisher Packt
ISBN-13 9781788992282
Length 318 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Soma Halder Soma Halder
Author Profile Icon Soma Halder
Soma Halder
Sinan Ozdemir Sinan Ozdemir
Author Profile Icon Sinan Ozdemir
Sinan Ozdemir
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Basics of Machine Learning in Cybersecurity FREE CHAPTER 2. Time Series Analysis and Ensemble Modeling 3. Segregating Legitimate and Lousy URLs 4. Knocking Down CAPTCHAs 5. Using Data Science to Catch Email Fraud and Spam 6. Efficient Network Anomaly Detection Using k-means 7. Decision Tree and Context-Based Malicious Event Detection 8. Catching Impersonators and Hackers Red Handed 9. Changing the Game with TensorFlow 10. Financial Fraud and How Deep Learning Can Mitigate It 11. Case Studies 12. Other Books You May Enjoy

SVM to detect malicious URLs

We will now use another machine learning approach to detect malicious URLs. Support vector machines (SVMs) are a popular method for classifying whether a URL is malicious or benign.

An SVM model classifies data across two or more hyperplanes. The output of the model is a hyperplane that can be used to segregate the input dataset, as shown in the following graph:

We then import the required packages. The SVM package available in the sklearn package (as shown in the following code) is very useful for this purpose:

#use SVM
from sklearn.svm import SVC
svmModel = SVC()
svmModel.fit(X_train, y_train)
#lsvcModel = svm.LinearSVC.fit(X_train, y_train)
svmModel.score(X_test, y_test)

Once the model is trained with the SVM classifier, we will again load the model and the feature vector to predict the URL's nature using the model, as shown in the following code...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image