Skip to content

Instantly share code, notes, and snippets.

@tianhuil
Last active November 8, 2019 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tianhuil/5cdbcb09c2853a8dab037805945ea5ad to your computer and use it in GitHub Desktop.
Save tianhuil/5cdbcb09c2853a8dab037805945ea5ad to your computer and use it in GitHub Desktop.
This is a Residual Regressor and Residual Classifier
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