Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: probability estimates are not available for loss='hinge'

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!

like image 733
user6769002 Avatar asked Aug 29 '16 07:08

user6769002


1 Answers

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)
like image 166
Lavanya Reddy Avatar answered Sep 24 '22 11:09

Lavanya Reddy