Created
September 24, 2016 13:37
-
-
Save mehdidc/e8de95be17cc8c4e05de0e1fc4aaec80 to your computer and use it in GitHub Desktop.
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
class EnsembleRegressor(object): | |
def __init__(self, regs=None): | |
self.regs = regs | |
def fit(self, X, y): | |
return self | |
def predict(self, X, return_std=False): | |
if return_std: | |
means = [] | |
stds = [] | |
for r in self.regs: | |
m, s = r.predict(X, return_std=True) | |
means.append(m) | |
stds.append(s) | |
means = np.vstack(means).T | |
stds = np.vstack(stds).T | |
return np.mean(means, axis=1), (np.sqrt((stds**2).sum(axis=1)) / stds.shape[1]) | |
else: | |
preds = np.vstack([r.predict(X) for r in self.regs]).T | |
return np.mean(preds, axis=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment