eckity.sklearn_compatible.sk_classifier

 1from sklearn.base import ClassifierMixin
 2from sklearn.utils.validation import check_is_fitted
 3
 4from eckity.sklearn_compatible.sklearn_wrapper import SklearnWrapper
 5from eckity.sklearn_compatible.classification_evaluator import ClassificationEvaluator
 6
 7
 8class SKClassifier(SklearnWrapper, ClassifierMixin):
 9    def predict(self, X):
10        """
11        Compute output using best evolved individual.
12        Use `predict` in a sklearn setting.
13        Input is a numpy array.
14
15        Parameters
16        ----------
17        X : array-like or sparse matrix of (num samples, num feautres)
18
19        Returns
20        -------
21        y : array, shape (num samples,)
22            Returns predicted values after applying classification.
23        """
24
25        # Check is fit had been called
26        check_is_fitted(self)
27
28        clf_eval: ClassificationEvaluator = self.algorithm.get_individual_evaluator()
29
30        # y doesn't matter since we only need execute result and evolution has already finished
31        clf_eval.set_context((X, None))
32
33        return clf_eval.classify_individual(self.algorithm.best_of_run_)
34
35    def predict_proba(self, X):
36        raise NotImplementedError('not implemented yet')
37
38    def predict_log_proba(self, X):
39        raise NotImplementedError('not implemented yet')
class SKClassifier(eckity.sklearn_compatible.sklearn_wrapper.SklearnWrapper, sklearn.base.ClassifierMixin):
 9class SKClassifier(SklearnWrapper, ClassifierMixin):
10    def predict(self, X):
11        """
12        Compute output using best evolved individual.
13        Use `predict` in a sklearn setting.
14        Input is a numpy array.
15
16        Parameters
17        ----------
18        X : array-like or sparse matrix of (num samples, num feautres)
19
20        Returns
21        -------
22        y : array, shape (num samples,)
23            Returns predicted values after applying classification.
24        """
25
26        # Check is fit had been called
27        check_is_fitted(self)
28
29        clf_eval: ClassificationEvaluator = self.algorithm.get_individual_evaluator()
30
31        # y doesn't matter since we only need execute result and evolution has already finished
32        clf_eval.set_context((X, None))
33
34        return clf_eval.classify_individual(self.algorithm.best_of_run_)
35
36    def predict_proba(self, X):
37        raise NotImplementedError('not implemented yet')
38
39    def predict_log_proba(self, X):
40        raise NotImplementedError('not implemented yet')

Sklearn-compatible wrapper to support evolution using sklearn methods.

Parameters
  • algorithm (Algorithm): Wrapped Evolutionary algorithm. The Wrapper invokes 'evolve' and 'execute' methods of the algorithm during the fitting and prediction process, respectively.
Attributes
  • is_fitted (bool): Determines if the model is fitted (evolved).
def predict(self, X):
10    def predict(self, X):
11        """
12        Compute output using best evolved individual.
13        Use `predict` in a sklearn setting.
14        Input is a numpy array.
15
16        Parameters
17        ----------
18        X : array-like or sparse matrix of (num samples, num feautres)
19
20        Returns
21        -------
22        y : array, shape (num samples,)
23            Returns predicted values after applying classification.
24        """
25
26        # Check is fit had been called
27        check_is_fitted(self)
28
29        clf_eval: ClassificationEvaluator = self.algorithm.get_individual_evaluator()
30
31        # y doesn't matter since we only need execute result and evolution has already finished
32        clf_eval.set_context((X, None))
33
34        return clf_eval.classify_individual(self.algorithm.best_of_run_)

Compute output using best evolved individual. Use predict in a sklearn setting. Input is a numpy array.

Parameters
  • X (array-like or sparse matrix of (num samples, num feautres)):
Returns
  • y (array, shape (num samples,)): Returns predicted values after applying classification.
def predict_proba(self, X):
36    def predict_proba(self, X):
37        raise NotImplementedError('not implemented yet')
def predict_log_proba(self, X):
39    def predict_log_proba(self, X):
40        raise NotImplementedError('not implemented yet')