Passed
Pull Request — master (#101)
by Simon
02:06
created

sklearn.GradientBoostingExperiment._score()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 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