
[code]

    from sklearn.ensemble import RandomForestClassifier
    import numpy as np
    
    clf=RandomForestClassifier()
    clf.fit(X_train,y_train)
    
    importances=clf.feature_importances_
    std= np.std([tree.feature_importances_ for tree in clf.estimators_],axis=0)
    indices= np.argsort(importances)[::-1]
    
    plt.figure()
    plt.title("Feature importances")
    plt.bar(np.array(X_train.columns)[indices],color="r",yerr=std[indices],align="center")
    plt.xticks(np.array(X_train.columns)[indices],ratation=45, ha="right")
    plt.xlim([-1,X.shape[1]])
    plt.show()
    
[/code]


CC BY-SA 4.0
2021-12-19T09:06:45.533
85229
2021-12-19T09:16:11.693
2021-12-19T09:16:11.693
3060
50570
question
python
'X_train' is not defined と表示されてしまいます。どのようにすれば良いでしょうか。