Recap: Server Watch
Part of the Unsupervised Learning section of Coddy's Machine Learning journey. Lesson 38 of 51.
Challenge
MediumA web server logged every minute of the night shift. Which minutes were truly strange?
- Scale the four
columns. - Flag minutes with an isolation forest (
contamination=0.03,random_state=0) and with LOF (n_neighbors=20,contamination=0.03). - Print the minutes both flag, in time order, as below.
- Scatter every minute, requests across, latency up, labelled
minutes. Circle the minutes both flag in red, labelledboth detectors. Add a legend and show.
For another night:
Both detectors flag 5 minutes:
00:25: 1116 requests/s, 186 ms
01:10: 2106 requests/s, 95 ms
02:00: 1151 requests/s, 133 ms
02:40: 835 requests/s, 142 ms
03:10: 1774 requests/s, 82 msCoddy then describes your chart.
Try it yourself
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import IsolationForest
from sklearn.neighbors import LocalOutlierFactor
# One row per minute of the night shift on a web server
log = pd.read_csv("servers.csv")
columns = ["cpu_pct", "memory_gb", "requests_per_s", "latency_ms"]
# Don't change the lines below
fig, ax = plt.subplots()
ax.set_title("Server Watch")
ax.set_xlabel("Requests per second")
ax.set_ylabel("Latency (ms)")
# Write your code below
All lessons in Unsupervised Learning
1Finding Groups
Learning Without LabelsMeasuring SimilarityK-Means by HandK-Means in scikit-learnRecap: Gym Members7PCA in Practice
Seeing 64 DimensionsComponents as PatternsCompress and RebuildPCA Before a ModelRecap: Face Scanner10Project: Digit Explorer
Look at the DigitsShrink with PCACluster the DigitsName the ClustersFind the Odd Ones8Anomaly Detection
Finding the Odd OnesIsolation ForestLocal Outlier FactorAnomaly ScoresRecap: Server WatchPractice on your own: Online Python compiler