Menu
CoddyTech

Recap: Server Watch

Part of the Unsupervised Learning section of Coddy's Machine Learning journey. Lesson 38 of 51.

challenge icon

Challenge

Medium

A web server logged every minute of the night shift. Which minutes were truly strange?

  1. Scale the four columns.
  2. Flag minutes with an isolation forest (contamination=0.03, random_state=0) and with LOF (n_neighbors=20, contamination=0.03).
  3. Print the minutes both flag, in time order, as below.
  4. Scatter every minute, requests across, latency up, labelled minutes. Circle the minutes both flag in red, labelled both 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 ms

A night of server minutes, requests per second across and latency up: a rising cloud, three slow minutes circled red above it and two busy ones far right

Coddy 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

Practice on your own: Online Python compiler