Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Data Analysis with Pandas

You're reading from   Hands-On Data Analysis with Pandas A Python data science handbook for data collection, wrangling, analysis, and visualization

Arrow left icon
Product type Paperback
Published in Apr 2021
Publisher Packt
ISBN-13 9781800563452
Length 788 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Stefanie Molin Stefanie Molin
Author Profile Icon Stefanie Molin
Stefanie Molin
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

Preface 1. Section 1: Getting Started with Pandas
2. Chapter 1: Introduction to Data Analysis FREE CHAPTER 3. Chapter 2: Working with Pandas DataFrames 4. Section 2: Using Pandas for Data Analysis
5. Chapter 3: Data Wrangling with Pandas 6. Chapter 4: Aggregating Pandas DataFrames 7. Chapter 5: Visualizing Data with Pandas and Matplotlib 8. Chapter 6: Plotting with Seaborn and Customization Techniques 9. Section 3: Applications – Real-World Analyses Using Pandas
10. Chapter 7: Financial Analysis – Bitcoin and the Stock Market 11. Chapter 8: Rule-Based Anomaly Detection 12. Section 4: Introduction to Machine Learning with Scikit-Learn
13. Chapter 9: Getting Started with Machine Learning in Python 14. Chapter 10: Making Better Predictions – Optimizing Models 15. Chapter 11: Machine Learning Anomaly Detection 16. Section 5: Additional Resources
17. Chapter 12: The Road Ahead 18. Solutions
19. Other Books You May Enjoy Appendix

Implementing rule-based anomaly detection

It's time to catch those hackers. After the EDA in the previous section, we have an idea of how we might go about this. In practice, this is much more difficult to do, as it involves many more dimensions, but we have simplified it here. We want to find the IP addresses with excessive amounts of attempts accompanied by low success rates, and those attempting to log in with more unique usernames than we would deem normal (anomalies). To do this, we will employ threshold-based rules as our first foray into anomaly detection; then, in Chapter 11, Machine Learning Anomaly Detection, we will explore a few machine learning techniques as we revisit this scenario.

Since we are interested in flagging IP addresses that are suspicious, we are going to arrange the data so that we have hourly aggregated data per IP address (if there was activity for that hour):

>>> hourly_ip_logs = log.assign(
...     failures...
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