Last active
November 8, 2019 22:54
-
-
Save tianhuil/5cdbcb09c2853a8dab037805945ea5ad to your computer and use it in GitHub Desktop.
This is a Residual Regressor and Residual Classifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.base import BaseEstimator, ClassifierMixin, RegressorMixin | |
class _ResidualEstimator(BaseEstimator): | |
def __init__(self, base, residual): | |
self.base = base | |
self.residual = residual | |
def fit(self, X, y): | |
self.base.fit(X, y) | |
self.residual.fit(X, y - self.base.predict(X)) | |
return self | |
def predict(self, X): | |
return self.base.predict(X) + self.residual.predict(X) | |
class ResidualRegressor(_ResidualEstimator, RegressorMixin): | |
pass | |
class ResidualClassifier(_ResidualEstimator, ClassifierMixin): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment