Abstract
Although few-shot learning and one-class classification (OCC), i.e., learning a binary classifier with data from only one class, have been separately well studied, their intersection remains rather unexplored. Our work addresses the few-shot OCC problem and presents a method to modify the episodic data sampling strategy of the model-agnostic meta-learning (MAML) algorithm to learn a model initialization particularly suited for learning few-shot OCC tasks. This is done by explicitly optimizing for an initialization which only requires few gradient steps with one-class minibatches to yield a performance increase on class-balanced test data. We provide a theoretical analysis that explains why our approach works in the few-shot OCC scenario, while other meta-learning algorithms fail, including the unmodified MAML. Our experiments on eight datasets from the image and time-series domains show that our method leads to better results than classical OCC and few-shot classification approaches, and demonstrate the ability to learn unseen tasks from only few normal class samples. Moreover, we successfully train anomaly detectors for a real-world application on sensor readings recorded during industrial manufacturing of workpieces with a CNC milling machine, by using few normal examples. Finally, we empirically demonstrate that the proposed data sampling technique increases the performance of more recent meta-learning algorithms in few-shot OCC and yields state-of-the-art results in this problem setting.
Introduction
Anomaly detection is typically framed as a One-Class Classification (OCC) problem, where a model is trained on abundant "normal" data to identify outliers. However, in many high-stakes domains—such as industrial manufacturing or rare disease diagnosis—even normal data can be extremely scarce. This creates a Few-Shot One-Class Classification (FS-OCC) challenge that standard methods struggle to solve.
Classical OCC methods (like OC-SVM) require substantial data to define a reliable boundary, while standard Few-Shot Learning (FSL) assumes access to examples from multiple classes during adaptation. In FS-OCC, the model only sees one class during the adaptation phase, leaving it with no reference for what constitutes an anomaly. This paper introduces OC-MAML, a framework that bridges this gap by modifying the meta-learning process to anticipate missing class information.
Methodology: One-Class MAML
The core innovation of OC-MAML lies in its modified episodic training strategy. Unlike standard MAML, which uses balanced classes in both the inner and outer loops, OC-MAML introduces a class mismatch:
- Inner Loop (Adaptation): The model is updated using a "support set" containing only examples from a single "normal" class.
- Outer Loop (Meta-Update): The model's performance is evaluated on a "query set" that is class-balanced (50% normal, 50% anomalies from other classes).
This discrepancy forces the meta-learning process to find a parameter initialization ($\theta$) where a single gradient step on one-class data moves the model toward a decision boundary capable of two-class discrimination.
Theoretical analysis reveals that second-order derivatives (Hessians) are essential for this process. OC-MAML explicitly maximizes the cosine similarity between gradients from one-class batches and class-balanced batches. This explains why first-order approximations like FOMAML or Reptile fail in this setting, as they lack the necessary information to "bridge" the gap between seeing one class and predicting two.
Experimental Results
The approach was validated across eight datasets, including image benchmarks (MiniImageNet, Omniglot) and real-world industrial sensor data (CNC-MMD).
OC-MAML consistently outperformed both classical and state-of-the-art baselines. For instance, on MiniImageNet with $K=10$ samples, classical methods like OC-SVM hovered near chance (51.2% accuracy), while OC-MAML achieved 76.2%. Furthermore, OC-MAML outperformed standard MAML by approximately 10-15% across most benchmarks.
In real-world applications, the model demonstrated high efficacy on the CNC milling dataset, achieving F1-scores between 80% and 95.9% using only 10 normal examples to adapt to new manufacturing tasks.
Conclusion
OC-MAML demonstrates that meta-learning can be effectively adapted for one-class problems by carefully designing the episodic sampling strategy. By leveraging second-order gradient information, the model learns to generalize from a single class to a robust anomaly detection boundary. Future work includes exploring unsupervised FS-OCC and reducing the computational overhead associated with Hessian calculations.
Summary updated