为了账号安全,请及时绑定邮箱和手机立即绑定

使用 SGD 分类器和 GridsearchCV 查找顶级特征

使用 SGD 分类器和 GridsearchCV 查找顶级特征

Smart猫小萌 2021-06-28 08:45:19
# Implementing Linear_SGD classifierclf = linear_model.SGDClassifier(max_iter=1000)Cs = [0.0001,0.001, 0.01, 0.1, 1, 10]tuned_parameters = [{'alpha': Cs}]model = GridSearchCV(clf, tuned_parameters, scoring = 'accuracy', cv=2)model.fit(x_train, Y_train)如何从下面的代码中找到最重要的功能,因为它显示了错误 feature_count_。这里我的向量化器是 BOW 和分类器是 SGDclassifier 与铰链损失def important_features(vectorizer,classifier,n=20):    class_labels = classifier.classes_    feature_names =vectorizer.get_feature_names()    topn_class1 = sorted(zip(classifier.feature_count_[0],     feature_names),reverse=True)[:n]    topn_class2 = sorted(zip(classifier.feature_count_[1],     feature_names),reverse=True)[:n]    print("Important words in negative reviews")我尝试使用上面的代码,但显示错误为AttributeError                            Traceback (most recent call last)<ipython-input-77-093048fb461e> in <module>()----> 1 important_features(Timesort_X_vec,model)<ipython-input-75-10b9d6ee3f81> in important_features(vectorizer, classifier, n)  2     class_labels = classifier.classes_  3     feature_names =vectorizer.get_feature_names()   ----> 4     topn_class1 = sorted(zip(classifier.feature_count_[0], feature_names),reverse=True)[:n]  5     topn_class2 = sorted(zip(classifier.feature_count_[1], feature_names),reverse=True)[:n]  6     print("Important words in negative reviews") AttributeError: 'GridSearchCV' object has no attribute 'feature_count_'.
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 247 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号