在MultinomialNB中选择重要功能时出错

时间:2019-05-29 10:50:40

标签: python

以下是我的代码:

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”

0 个答案:

没有答案