从随机森林导出特征重要性到CSV



嗨,我想创建一个有2列的。csv:随机森林模型的特征重要性和该特征的名称。并确保数值和变量名之间的匹配是正确的

这是一个例子但是我不能正确地导出为。csv

test_features = test[["area","product", etc.]].values
# Create the target 
target = test["churn"].values
pred_forest = my_forest.predict(test_features)
# Print the score of the fitted random forest
print(my_forest.score(test_features, target))

importance = my_forest.feature_importances_

pd.DataFrame({"IMP": importance, "features":test_features }).to_csv('forest_0407.csv',index=False)

使用

x = list(zip(my_forest.feature_importances_,list of features you are using))
x = pandas.DataFrame(x,columns=["Importance","Feature_Name"])

相关内容

  • 没有找到相关文章

最新更新