How to implement a custom predict function in sklearn

Viewed 21

I am implementing a custom estimator for piecewise linear regression in sklearn. For prediction, I need to check the test data value and map it to the corresponding interval obtained in the training phase. My train and test data are in ascending order. For example below is the intervals after training:

#interval max value in training set
1 100
2 120
3 150

My test data is: 50, 80, 130, 135

Then the observations 50, 80 must be predicted from the 1st interval (since they are less than 100), 130, 135 must be predicted using the 3rd interval, and so on.

My question is: how can I override the predict function? I have read the docs, Developing scikit-learn estimators, Metrics and scoring: quantifying the quality of predictions but could not understand how to implement a prediction method.

0 Answers
Related