| Total Complexity | 4 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from sklearn.model_selection import cross_val_score |
||
| 2 | from sklearn.ensemble import GradientBoostingRegressor |
||
| 3 | |||
| 4 | |||
| 5 | from hyperactive import BaseExperiment |
||
| 6 | |||
| 7 | |||
| 8 | class SklearnExperiment(BaseExperiment): |
||
| 9 | def __init__(self, estimator, X, y, cv=4): |
||
| 10 | super().__init__() |
||
| 11 | |||
| 12 | self.estimator = estimator |
||
| 13 | self.X = X |
||
| 14 | self.y = y |
||
| 15 | self.cv = cv |
||
| 16 | |||
| 17 | def _score(self, **params): |
||
| 18 | model = self.estimator(**params) |
||
| 19 | scores = cross_val_score(model, self.X, self.y, cv=self.cv) |
||
| 20 | return scores.mean() |
||
| 21 | |||
| 22 | |||
| 23 | class GradientBoostingExperiment(BaseExperiment): |
||
| 24 | def __init__(self, X, y, cv=4): |
||
| 25 | super().__init__() |
||
| 26 | |||
| 27 | self.estimator = GradientBoostingRegressor # The user could also predefine the estimator |
||
| 28 | self.X = X |
||
| 29 | self.y = y |
||
| 30 | self.cv = cv |
||
| 31 | |||
| 32 | def _score(self, **params): |
||
| 33 | model = self.estimator(**params) |
||
| 34 | scores = cross_val_score(model, self.X, self.y, cv=self.cv) |
||
| 35 | return scores.mean() |
||
| 36 |