如果我们在 SGDclassifier 上使用线性核的校准 cv,如何获得特征权重

how to get the feature weight if we use calibrated cv for linear kernal on SGD classifier

我在 SGD 分类器上为我的线性核使用校准的 cv,因为我的损失是铰链损失。但现在我想获得前 10 项功能或 类,那么该怎么做,我尝试使用 .coef_ 但它没有抛出错误。

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' object has no attribute 'coef_'

在校准模型之前,只需 .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)

然后你就可以访问系数了。