python - 在 MultinomialNB 中选择重要特征时出错
问题描述
以下是我的代码:
feature_names1 = np.hstack([text_bow_train,title_bow_train,X_train_cat_ohe,X_train_subcat_ohe, X_train_state_ohe, X_train_pre_ohe, X_train_grade_ohe, "Price","Number of Previously posted project","Quantity"])
def most_important_features(vectorizer, classifier, n=5):
class_labels = classifier.classes_
feature_names = vectorizer.get_feature_names()
topn_class1 = sorted(zip(classifier.coef_[0], feature_names))[:n]
topn_class2 = sorted(zip(classifier.coef_[0], feature_names))[-n:]
for coef, feat in topn_class1:
print(class_labels[0], coef, feat)
for coef, feat in reversed(topn_class2):
print(class_labels[1], coef, feat)
most_important_features(feature_names1, mnb)
我收到以下错误:
AttributeError:“numpy.ndarray”对象没有属性“get_feature_names”
解决方案
推荐阅读
- c# - 加载然后卸载具有依赖关系的 DLL 会锁定 DLL
- python - Python脚本通过SQlite从Mac上的本地网络读取数据库文件
- .net - .net 的 JSON 到 JSON 转换库
- jmeter - 与浏览器相比,缓存请求从缓存中检索 124 个嵌入式资源的 Jmeter 响应时间非常长
- javascript - 如何使用旋转找出旋转梯形的边界框
- xamarin.forms - 按 ID 查找视图
(Resource.Id.toolbar) 返回 null - asp.net - Web 配置重定向 HTTP 和 www 需要忽略 localhost
- reactjs - 如何在 Next.js 中的路由之间使用共享组件
- php - 具有多个 where 子句的 Laravel 查询范围返回不正确的数据
- drupal - 出现错误:EntityMetadataWrapperException:未知数据属性 group_access