Jack is building an early-warning system for unusual server activity. He is using the following variables gathered from server access logs:
from scripts import make_logs
logs = make_logs(inlierCount=1000, outlierCount=10)
inliers = logs.data[:1000]
outliers = logs.data[1000:]
from sklearn import svm
model = svm.OneClassSVM(nu=0.1, kernel='rbf', gamma=0.1)
model.fit(inliers)
model.predict(inliers[0])
model.predict(outliers[0])
predictions = model.predict(inliers)
errors = predictions[predictions == -1].size
print 'Error rate: %s %%' % (100 * errors / float(len(predictions)))
model.predict(outliers)