Code Duplication    Length = 19-32 lines in 2 locations

src/hyperactive/integrations/sklearn/sklearn_cv_experiment.py 1 location

@@ 28-59 (lines=32) @@
25
        """
26
        return list(self.estimator.get_params().keys())
27
28
    def _score(self, **params):
29
        """Score the parameters.
30
31
        Parameters
32
        ----------
33
        params : dict with string keys
34
            Parameters to score.
35
36
        Returns
37
        -------
38
        float
39
            The score of the parameters.
40
        dict
41
            Additional metadata about the search.
42
        """
43
        estimator = clone(self.estimator)
44
        estimator.set_params(**params)
45
46
        cv_results = cross_validate(
47
            self.estimator,
48
            self.X,
49
            self.y,
50
            cv=self.cv,
51
        )
52
53
        add_info_d = {
54
            "score_time": cv_results["score_time"],
55
            "fit_time": cv_results["fit_time"],
56
            "n_test_samples": _num_samples(self.X),
57
        }
58
59
        return cv_results["test_score"].mean(), add_info_d
60

src/hyperactive/integrations/sklearn/objective_function_adapter.py 1 location

@@ 23-41 (lines=19) @@
20
        self.scoring = scoring
21
        self.cv = cv
22
23
    def objective_function(self, params):
24
25
        estimator = clone(self.estimator)
26
        estimator.set_params(**params)
27
28
        cv_results = cross_validate(
29
            estimator,
30
            self.X,
31
            self.y,
32
            cv=self.cv,
33
        )
34
35
        add_info_d = {
36
            "score_time": cv_results["score_time"],
37
            "fit_time": cv_results["fit_time"],
38
            "n_test_samples": _num_samples(self.X),
39
        }
40
41
        return cv_results["test_score"].mean(), add_info_d
42