BestEstimator.inverse_transform()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nop 3
1
"""Best estimator utilities for scikit-learn integration.
2
3
Author: Simon Blanke
4
Email: [email protected]
5
License: MIT License
6
"""
7
8
from sklearn.utils.metaestimators import available_if
9
from sklearn.utils.validation import check_is_fitted
10
11
from ._compat import _deprecate_Xt_in_inverse_transform
12
from .utils import _estimator_has
13
14
15
# NOTE Implementations of following methods from:
16
# https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/model_selection/_search.py
17
# Tag: 1.5.1
18
class BestEstimator:
19
    """BestEstimator class."""
20
21
    @available_if(_estimator_has("score_samples"))
22
    def score_samples(self, X):
23
        """Score Samples function."""
24
        check_is_fitted(self)
25
        return self.best_estimator_.score_samples(X)
26
27
    @available_if(_estimator_has("predict"))
28
    def predict(self, X):
29
        """Predict function."""
30
        check_is_fitted(self)
31
        return self.best_estimator_.predict(X)
32
33
    @available_if(_estimator_has("predict_proba"))
34
    def predict_proba(self, X):
35
        """Predict Proba function."""
36
        check_is_fitted(self)
37
        return self.best_estimator_.predict_proba(X)
38
39
    @available_if(_estimator_has("predict_log_proba"))
40
    def predict_log_proba(self, X):
41
        """Predict Log Proba function."""
42
        check_is_fitted(self)
43
        return self.best_estimator_.predict_log_proba(X)
44
45
    @available_if(_estimator_has("decision_function"))
46
    def decision_function(self, X):
47
        """Decision Function function."""
48
        check_is_fitted(self)
49
        return self.best_estimator_.decision_function(X)
50
51
    @available_if(_estimator_has("transform"))
52
    def transform(self, X):
53
        """Transform function."""
54
        check_is_fitted(self)
55
        return self.best_estimator_.transform(X)
56
57
    @available_if(_estimator_has("inverse_transform"))
58
    def inverse_transform(self, X=None, Xt=None):
59
        """Inverse Transform function."""
60
        X = _deprecate_Xt_in_inverse_transform(X, Xt)
61
        check_is_fitted(self)
62
        return self.best_estimator_.inverse_transform(X)
63
64
    @property
65
    def classes_(self):
66
        """Classes  function."""
67
        _estimator_has("classes_")(self)
68
        return self.best_estimator_.classes_
69