You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defdecision_function(self, X):
""" Predict confidence scores for samples. The confidence score for a sample is the signed distance of that sample to the hyperplane. Parameters ---------- X : array-like or sparse matrix, shape (n_samples, n_features) Samples. Returns ------- array, shape=(n_samples,) if n_classes == 2 else (n_samples, n_classes) Confidence scores per (sample, class) combination. In the binary case, confidence score for self.classes_[1] where >0 means this class would be predicted. """check_is_fitted(self)
X=check_array(X, accept_sparse='csr')
n_features=self.coef_.shape[1]
ifX.shape[1] !=n_features:
raiseValueError("X has %d features per sample; expecting %d"% (X.shape[1], n_features))
scores=safe_sparse_dot(X, self.coef_.T,
dense_output=True) +self.intercept_returnscores.ravel() ifscores.shape[1] ==1elsescoresdefpredict(self, X):
""" Predict class labels for samples in X. Parameters ---------- X : array-like or sparse matrix, shape (n_samples, n_features) Samples. Returns ------- C : array, shape [n_samples] Predicted class label per sample. """scores=self.decision_function(X)
iflen(scores.shape) ==1:
indices= (scores>0).astype(int)
else:
indices=scores.argmax(axis=1)
returnself.classes_[indices]