小编Abd*_*den的帖子

管道'对象没有属性'feature_importances_

我的代码有问题,我想查看 word2vec 模型中向量的特征重要性,但我不能,因为它是一个管道。有人可以帮我找到解决方案吗?

## Import the random forest model.
from sklearn.ensemble import RandomForestClassifier  
## This line instantiates the model. 
rf = Pipeline([
    ("word2vec vectorizer", MeanEmbeddingVectorizer(w2v)),
    ("Random_forest",  RandomForestClassifier(n_estimators=100, max_depth=6,random_state=0))])
## Fit the model on your training data.
rf.fit(X_train, y_train) 
## And score it on your testing data.
rf.score(X_test, y_test)

X = model.wv.syn0
X = X.astype(int)

def plot_feat_imp(model, X): 
    Feature_Imp = pd.DataFrame([X, rand_w2v_tfidf.feature_importances_]).transpose(
    ).sort_values(1, ascending=False)
    plt.figure(figsize=(14, 7))
    sns.barplot(y=Feature_Imp.loc[:, 0], x=Feature_Imp.loc[:, 1], data=Feature_Imp, orient='h')
    plt.title("Importance des variables (qu'est ce qui explique le mieux …
Run Code Online (Sandbox Code Playgroud)

jupyter-notebook

5
推荐指数
1
解决办法
8396
查看次数

标签 统计

jupyter-notebook ×1