Feature: Add Support for LocalOutlierFactor in Sklearn Serializer
Summary
The OpenModels sklearn serializer currently does not support the LocalOutlierFactor (LOF) estimator from scikit-learn. Attempting to serialize or deserialize a LocalOutlierFactor instance results in an AttributeError: This 'LocalOutlierFactor' has no attribute 'predict'. This is because LOF does not implement a predict method unless novelty=True, and its API differs from most other estimators.
Motivation
- Completeness:
LocalOutlierFactor is a widely used anomaly detection algorithm and should be supported by the serializer.
- User Experience: Users expect all standard scikit-learn estimators to be serializable/deserializable without errors, including those with non-standard APIs.
- Correctness: The serializer should handle estimators that do not implement
predict or have special requirements for serialization.
Error Details
- Error:
AttributeError: This 'LocalOutlierFactor' has no attribute 'predict'
- Context:
This error occurs because LocalOutlierFactor only exposes a predict method if it is constructed with novelty=True. Otherwise, it is intended for outlier detection on the training set only, using fit_predict and negative_outlier_factor_.
References
Suggested Tasks
- Investigate the internal structure and API of
LocalOutlierFactor, especially the difference in behavior when novelty=True vs novelty=False.
- Update the serializer to correctly handle serialization and deserialization of
LocalOutlierFactor, including its fitted attributes (e.g., negative_outlier_factor_, n_neighbors_, etc.).
- Ensure that the absence of a
predict method when novelty=False does not cause errors during serialization or deserialization.
- Add tests to ensure that
LocalOutlierFactor can be round-tripped (serialized and deserialized) for both novelty=True and novelty=False cases.
- Remove
"LocalOutlierFactor" from the NOT_SUPPORTED_ESTIMATORS list in sklearn_serializer.py once support is complete.
Acceptance Criteria
LocalOutlierFactor can be serialized and deserialized without errors for both novelty=True and novelty=False.
- All relevant parameters and fitted attributes are preserved.
- Tests are added to cover typical usage of
LocalOutlierFactor.
"LocalOutlierFactor" is no longer listed in NOT_SUPPORTED_ESTIMATORS.
Related file: openmodels/serializers/sklearn/sklearn_serializer.py
Feature: Add Support for
LocalOutlierFactorin Sklearn SerializerSummary
The OpenModels sklearn serializer currently does not support the
LocalOutlierFactor(LOF) estimator from scikit-learn. Attempting to serialize or deserialize aLocalOutlierFactorinstance results in anAttributeError: This 'LocalOutlierFactor' has no attribute 'predict'. This is because LOF does not implement apredictmethod unlessnovelty=True, and its API differs from most other estimators.Motivation
LocalOutlierFactoris a widely used anomaly detection algorithm and should be supported by the serializer.predictor have special requirements for serialization.Error Details
AttributeError: This 'LocalOutlierFactor' has no attribute 'predict'This error occurs because
LocalOutlierFactoronly exposes apredictmethod if it is constructed withnovelty=True. Otherwise, it is intended for outlier detection on the training set only, usingfit_predictandnegative_outlier_factor_.References
Suggested Tasks
LocalOutlierFactor, especially the difference in behavior whennovelty=Truevsnovelty=False.LocalOutlierFactor, including its fitted attributes (e.g.,negative_outlier_factor_,n_neighbors_, etc.).predictmethod whennovelty=Falsedoes not cause errors during serialization or deserialization.LocalOutlierFactorcan be round-tripped (serialized and deserialized) for bothnovelty=Trueandnovelty=Falsecases."LocalOutlierFactor"from theNOT_SUPPORTED_ESTIMATORSlist insklearn_serializer.pyonce support is complete.Acceptance Criteria
LocalOutlierFactorcan be serialized and deserialized without errors for bothnovelty=Trueandnovelty=False.LocalOutlierFactor."LocalOutlierFactor"is no longer listed inNOT_SUPPORTED_ESTIMATORS.Related file:
openmodels/serializers/sklearn/sklearn_serializer.py