π οΈ Implementing Custom Methods#
This section explains how to implement custom anomaly detection methods for each of the five PdM experiment flavors.
The framework provides base interfaces that your custom method must implement. Each flavor requires different components, but they follow the same general pattern:
Inherit from the appropriate interface (Unsupervised, Semi-supervised, Supervised)
Implement required methods (fit, predict, predict_one, get_params, etc.)
Handle per-source models (most methods maintain separate models for each data source)
Return scores in the expected format (float or list of floats)
Key Concepts#
Method Interfaces: Each method must inherit from one of five base interfaces:
π Implementing Unsupervised Methods β For unsupervised anomaly detection (online learning)
π Implementing Semi-Supervised Methods β For semi-supervised detection (profile-based learning)
π― Implementing Classification Methods β For supervised binary classification
β±οΈ Implementing RUL Regression Methods β For Remaining Useful Life regression
𧬠Implementing Survival Analysis Methods β For survival analysis and censoring
Method Requirements:
Every method must:
Accept
event_preferencesin__init__Maintain
model_per_sourcedictionary to store models per data sourceImplement
predict()to score entire datasetsImplement
predict_one()to score individual samples (for online settings)Implement
get_params()to return configuration dictionaryImplement
__str__()to return human-readable method nameReturn scores as float values (or specific structured formats for survival analysis)
Which Flavor Should I Implement For?#
Choose based on your use case:
Detect anomalies without labeled data. Good for discovering novel patterns.
Example: Isolation Forest with sliding windows
Learn from clean profiles, adapt with events. Good for typical operational data.
Example: Local Outlier Factor trained on profile data
Binary classifier: normal vs anomalous. Requires labeled training data.
Example: XGBoost trained on annotated sensor readings
Predict remaining useful life as a regression target.
Example: XGBoost regressor trained on time-to-failure labels
Model time-to-event with censoring and survival curves.
Example: Cox Proportional Hazards model
Implementation Workflow#
For each flavor, follow these steps:
Create a new class file in
pdmlabs/method/(e.g.,my_detector.py)Import the interface (e.g.,
from pdmlabs.method.unsupervised_method import UnsupervisedMethodInterface)Inherit from interface and implement all required abstract methods
Test with a simple dataset to verify prediction format
Integrate into experiments using the frameworkβs pipeline utilities
Register in
pdmlabs/method/__init__.pyif desired
Common Patterns#
Storing Models Per Source:
def fit(self, historic_data, historic_sources, event_data, anomaly_ranges):
for data, source, labels in zip(historic_data, historic_sources, anomaly_ranges):
# Train one model per source
model = SomeAlgorithm()
model.fit(data, labels)
self.model_per_source[source] = model
Predicting with Source Lookup:
def predict(self, target_data, source, event_data):
model = self.model_per_source[source]
scores = model.predict_proba(target_data)
return scores[:, 1].tolist() # Return as list of floats
Getting Hyperparameters:
def get_params(self):
return self.model_per_source[list(self.model_per_source.keys())[0]].get_params()
See Detailed Guides#
Select your experiment flavor below to learn how to implement a custom method: