I'm trying to use Vetiver to deploy an isolation forest model (for anomaly detection) to an API endpoint.
All is going well by adapting the example here.
However, when deployed, the endpoint uses the model.predict()
method by default (which returns 1 for normal or -1 for anomaly).
I want the model to return a score between 0 and 1 as given by the model.score_samples()
method.
Does anybody know how I can configure the Vetiver endpoint such that it uses .score_samples()
rather than .predict()
for scoring?
Thanks
vetiver.predict()
primarily acts as a router to an API endpoint, so it does not have to have the same behavior asmodel.predict()
. You can overload what functionvetiver.predict()
uses on your model by defining a custom handler.In your case, an implementation might look something like below.
Initialize your custom handler and pass it into
VetiverModel()
.Then, when you use the
vetiver.predict()
function, it will return the values formodel.score_samples()
, rather thanmodel.predict()
.