linear_svm_sgd=SGDClassifier(penalty=penalty,alpha=i,max_iter=1000,class_weight='balanced')
calibrated_clf= CalibratedClassifierCV(linear_svm_sgd,cv=3, method='sigmoid')
#fit the model on train and predict its probability
clf_model=calibrated_clf.fit(xtrain_bow,ytrain_bow)
predictl1=clf_model.predict_proba(xtrain_bow)
fp_rate, tp_rate, thresholds = roc_curve(ytrain_bow, predictl1[:,1])
#fit the model on cv & predict its probablity
clf_model=calibrated_clf.fit(xcv_bow,ycv_bow)
fp_rate_cv, tp_rate_cv, thresholds = roc_curve(ycv_bow,clf_model.predict_proba(xcv_bow)[:,1])
#saving the value for hyperparamater foe each penalty l1 & l2
if penalty=="l1":
auc_valuel1_train.append(auc(fp_rate,tp_rate))
auc_valuel1_cv.append(auc(fp_rate_cv,tp_rate_cv))
else:
auc_valuel2_train.append(auc(fp_rate,tp_rate))
auc_valuel2_cv.append(auc(fp_rate_cv,tp_rate_cv))
这给了我以下错误
Top10_features=linear_svm_sgd.coef_
AttributeError:“ SGDClassifier”对象没有属性“ coef _”
答案 0 :(得分:1)
在校准模型之前,只需.fit
SGDClassifier。
linear_svm_sgd.fit(xtrain_bow, ytrain_bow)
calibrated_clf= CalibratedClassifierCV(linear_svm_sgd,cv=3, method='sigmoid')
#fit the model on train and predict its probability
clf_model=calibrated_clf.fit(xtrain_bow,ytrain_bow)
predictl1=clf_model.predict_proba(xtrain_bow)
然后您将可以使用系数。