text_clf = Pipeline([('vect',CountVectorizer(decode_error='ignore')),
('tfidf',TfidfTransformer()),
('clf',SGDClassifier(loss = 'hinge',penalty = 'elasticnet',alpha = 1e-3,n_iter = 10, random_state = 40))])
text_clf = text_clf.fit(trainDocs+valDocs,np.array(trainLabels+valLabels))
predicted = text_clf.predict_proba(testDocs)
How can I get the predicted probability of every test sample? Thanks!
SGDClassifier(loss = 'hinge')
does not have probability by default.
You have to pass SGDclassifier(loss = 'hinge')
to CalibratedClassifierCV()
which will calculate the probability values of SGDclassifier(loss = 'hinge')
.
lr = SGDClassifier(loss='hinge',alpha=best_alpha,class_weight='balanced')
clf =lr.fit(X_tr, y_train)
calibrator = CalibratedClassifierCV(clf, cv='prefit')
model=calibrator.fit(X_tr, y_train)
y_train_pred = model.predict_proba(X_tr)
y_test_pred = model.predict_proba(X_te)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With