May 2020
Intermediate to advanced
530 pages
17h 8m
English
The Shark-ML library also implements the OCSVM algorithm for anomaly detection. In this case, the OneClassSvmTrainer and the KernelExpansion classes implement the algorithm. The following example shows how it works:
UnlabeledData<RealVector> data; importCSV(data, dataset_name); // separate last two samples in test dataset data.splitBatch(0, 50); auto test_data = data.splice(1); double gamma = 0.5; // kernel bandwidth parameter GaussianRbfKernel<> kernel(gamma); KernelExpansion<RealVector> ke(&kernel); double nu = 0.5; // parameter of the method for controlling the //smoothness of the solution OneClassSvmTrainer<RealVector> trainer(&kernel, nu); trainer.stoppingCondition().minAccuracy = 1e-6; trainer.train(ke, data); ...
Read now
Unlock full access