| 1 |  |  | # Author: Simon Blanke | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | # Email: [email protected] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | # License: MIT License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | from sklearn.utils.metaestimators import available_if | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | from sklearn.utils.deprecation import _deprecate_Xt_in_inverse_transform | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | from sklearn.exceptions import NotFittedError | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | from sklearn.utils.validation import check_is_fitted | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | from .utils import _estimator_has | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | # NOTE Implementations of following methods from: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | # https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/model_selection/_search.py | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | # Tag: 1.5.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | class BestEstimator: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     @available_if(_estimator_has("score_samples")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     def score_samples(self, X): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         check_is_fitted(self) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         return self.best_estimator_.score_samples(X) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     @available_if(_estimator_has("predict")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     def predict(self, X): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         check_is_fitted(self) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         return self.best_estimator_.predict(X) | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     @available_if(_estimator_has("predict_proba")) | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |     def predict_proba(self, X): | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |         check_is_fitted(self) | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         return self.best_estimator_.predict_proba(X) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     @available_if(_estimator_has("predict_log_proba")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     def predict_log_proba(self, X): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         check_is_fitted(self) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         return self.best_estimator_.predict_log_proba(X) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     @available_if(_estimator_has("decision_function")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     def decision_function(self, X): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         check_is_fitted(self) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         return self.best_estimator_.decision_function(X) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     @available_if(_estimator_has("transform")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     def transform(self, X): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         check_is_fitted(self) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         return self.best_estimator_.transform(X) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     @available_if(_estimator_has("inverse_transform")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     def inverse_transform(self, X=None, Xt=None): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         X = _deprecate_Xt_in_inverse_transform(X, Xt) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         check_is_fitted(self) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         return self.best_estimator_.inverse_transform(X) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     @property | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     def classes_(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         _estimator_has("classes_")(self) | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 58 |  |  |         return self.best_estimator_.classes_ | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |  |