One-class SVM for anomaly detection.
This is a stochastic implementation of the one-class SVM algorithm, and will not exactly match its batch formulation.
It is encouraged to scale the data upstream with
preprocessing.StandardScaler, as well as use
feature_extraction.RBFSampler to capture non-linearities.
nu – defaults to
An upper bound on the fraction of training errors and a lower bound of the fraction of support vectors. You can think of it as the expected fraction of anomalies.
optimizer (optim.Optimizer) – defaults to
The sequential optimizer used for updating the weights.
intercept_lr (Union[optim.schedulers.Scheduler, float]) – defaults to
Learning rate scheduler used for updating the intercept. A
optim.schedulers.Constantis used if a
floatis provided. The intercept is not updated when this is set to 0.
clip_gradient – defaults to
Clips the absolute value of each gradient value.
initializer (optim.initializers.Initializer) – defaults to
Weights initialization scheme.
>>> from river import anomaly >>> from river import compose >>> from river import datasets >>> from river import metrics >>> from river import preprocessing >>> model = anomaly.QuantileThresholder( ... anomaly.OneClassSVM(nu=0.2), ... q=0.995 ... ) >>> auc = metrics.ROCAUC() >>> for x, y in datasets.CreditCard().take(2500): ... score = model.score_one(x) ... model = model.learn_one(x) ... auc = auc.update(y, score) >>> auc ROCAUC: 0.747398
Return a fresh estimator with the same parameters.
The clone has the same parameters but has not been updated with any data. This works by looking at the parameters from the class signature. Each parameter is either - recursively cloned if it's a River classes. - deep-copied via
copy.deepcopy if not. If the calling object is stochastic (i.e. it accepts a seed parameter) and has not been seeded, then the clone will not be idempotent. Indeed, this method's purpose if simply to return a new instance with the same input parameters.
Update the model.
- x (dict)
Return an outlier score.
A high score is indicative of an anomaly. A low score corresponds a normal observation.
An anomaly score. A high score is indicative of an anomaly. A low score corresponds a