Reputation: 348
I know the SVM (specifically linear SVC) has an option namely when probability = True
as an optional parameter when you instantiate, model.predict_proba()
is supposed to give the probability of each of its predictions along with the label (1 or 0). However I keep getting the numpy error "use all() on an 1 dimensional array"
when I call predict_proba()
and I can only figure out how to get a prediction in the form of a label (1 or 0) using model.predict()
.
Upvotes: 2
Views: 1646
Reputation: 898
You can use CallibratedClassifierCV.
from sklearn.calibration import CalibratedClassifierCV
model_svc = LinearSVC()
model = CalibratedClassifierCV(model_svc)
model.fit(X_train, y_train)
pred_class = model.predict(y_test)
probability = model.predict_proba(predict_vec)
You will get predicted probability score in array values.
Upvotes: 0
Reputation: 2768
Documentation example works fine for me setting the flag probability=True
. The problem has to be in your input data. Try this very simple example:
import numpy as np
X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])
y = np.array([1, 1, 2, 2])
from sklearn.svm import SVC
clf = SVC(probability=True)
clf.fit(X, y)
print(clf.predict([[-0.8, -1]]))
print(clf.predict_proba([[-0.8, -1]]))
Upvotes: 3