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 ( 6 ClassificationEvaluator, 7) 8 9 10class SKClassifier(SklearnWrapper, ClassifierMixin): 11 def predict(self, X): 12 """ 13 Compute output using best evolved individual. 14 Use `predict` in a sklearn setting. 15 Input is a numpy array. 16 17 Parameters 18 ---------- 19 X : array-like or sparse matrix of (num samples, num feautres) 20 21 Returns 22 ------- 23 y : array, shape (num samples,) 24 Returns predicted values after applying classification. 25 """ 26 27 # Check is fit had been called 28 check_is_fitted(self) 29 30 clf_eval: ClassificationEvaluator = ( 31 self.algorithm.get_individual_evaluator() 32 ) 33 34 # ignore y since we only need execute result and evolution is finished 35 clf_eval.set_context((X, None)) 36 37 return clf_eval.classify_individual(self.algorithm.best_of_run_) 38 39 def predict_proba(self, X): 40 raise NotImplementedError("not implemented yet") 41 42 def predict_log_proba(self, X): 43 raise NotImplementedError("not implemented yet")
class
SKClassifier(eckity.sklearn_compatible.sklearn_wrapper.SklearnWrapper, sklearn.base.ClassifierMixin):
11class SKClassifier(SklearnWrapper, ClassifierMixin): 12 def predict(self, X): 13 """ 14 Compute output using best evolved individual. 15 Use `predict` in a sklearn setting. 16 Input is a numpy array. 17 18 Parameters 19 ---------- 20 X : array-like or sparse matrix of (num samples, num feautres) 21 22 Returns 23 ------- 24 y : array, shape (num samples,) 25 Returns predicted values after applying classification. 26 """ 27 28 # Check is fit had been called 29 check_is_fitted(self) 30 31 clf_eval: ClassificationEvaluator = ( 32 self.algorithm.get_individual_evaluator() 33 ) 34 35 # ignore y since we only need execute result and evolution is finished 36 clf_eval.set_context((X, None)) 37 38 return clf_eval.classify_individual(self.algorithm.best_of_run_) 39 40 def predict_proba(self, X): 41 raise NotImplementedError("not implemented yet") 42 43 def predict_log_proba(self, X): 44 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):
12 def predict(self, X): 13 """ 14 Compute output using best evolved individual. 15 Use `predict` in a sklearn setting. 16 Input is a numpy array. 17 18 Parameters 19 ---------- 20 X : array-like or sparse matrix of (num samples, num feautres) 21 22 Returns 23 ------- 24 y : array, shape (num samples,) 25 Returns predicted values after applying classification. 26 """ 27 28 # Check is fit had been called 29 check_is_fitted(self) 30 31 clf_eval: ClassificationEvaluator = ( 32 self.algorithm.get_individual_evaluator() 33 ) 34 35 # ignore y since we only need execute result and evolution is finished 36 clf_eval.set_context((X, None)) 37 38 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
set_partial_fit_request(unknown):
Descriptor for defining set_{method}_request methods in estimators.
New in version 1.3.
Parameters
- name (str):
The name of the method for which the request function should be
created, e.g.
"fit"would create aset_fit_requestfunction. - keys (list of str):
A list of strings which are accepted parameters by the created
function, e.g.
["sample_weight"]if the corresponding method accepts it as a metadata. - validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes
This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.
References
def
set_score_request(unknown):
Descriptor for defining set_{method}_request methods in estimators.
New in version 1.3.
Parameters
- name (str):
The name of the method for which the request function should be
created, e.g.
"fit"would create aset_fit_requestfunction. - keys (list of str):
A list of strings which are accepted parameters by the created
function, e.g.
["sample_weight"]if the corresponding method accepts it as a metadata. - validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes
This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.