Decision function for the OneVsOneClassifier. The decision values for the samples are computed by adding the normalized sum of pair-wise classification confidence levels to the votes in order to disambiguate between the decision values when the votes for all the clas
(self, X)
| 953 | return self.classes_[Y.argmax(axis=1)] |
| 954 | |
| 955 | def decision_function(self, X): |
| 956 | """Decision function for the OneVsOneClassifier. |
| 957 | |
| 958 | The decision values for the samples are computed by adding the |
| 959 | normalized sum of pair-wise classification confidence levels to the |
| 960 | votes in order to disambiguate between the decision values when the |
| 961 | votes for all the classes are equal leading to a tie. |
| 962 | |
| 963 | Parameters |
| 964 | ---------- |
| 965 | X : array-like of shape (n_samples, n_features) |
| 966 | Input data. |
| 967 | |
| 968 | Returns |
| 969 | ------- |
| 970 | Y : array-like of shape (n_samples, n_classes) or (n_samples,) |
| 971 | Result of calling `decision_function` on the final estimator. |
| 972 | |
| 973 | .. versionchanged:: 0.19 |
| 974 | output shape changed to ``(n_samples,)`` to conform to |
| 975 | scikit-learn conventions for binary classification. |
| 976 | """ |
| 977 | check_is_fitted(self) |
| 978 | X = validate_data( |
| 979 | self, |
| 980 | X, |
| 981 | accept_sparse=True, |
| 982 | ensure_all_finite=False, |
| 983 | reset=False, |
| 984 | ) |
| 985 | |
| 986 | indices = self.pairwise_indices_ |
| 987 | if indices is None: |
| 988 | Xs = [X] * len(self.estimators_) |
| 989 | else: |
| 990 | Xs = [X[:, idx] for idx in indices] |
| 991 | |
| 992 | predictions = np.vstack( |
| 993 | [est.predict(Xi) for est, Xi in zip(self.estimators_, Xs)] |
| 994 | ).T |
| 995 | confidences = np.vstack( |
| 996 | [_predict_binary(est, Xi) for est, Xi in zip(self.estimators_, Xs)] |
| 997 | ).T |
| 998 | Y = _ovr_decision_function(predictions, confidences, len(self.classes_)) |
| 999 | if self.n_classes_ == 2: |
| 1000 | return Y[:, 1] |
| 1001 | return Y |
| 1002 | |
| 1003 | @property |
| 1004 | def n_classes_(self): |