您好我想创建一个包含2列的.csv:随机林模型的功能重要性以及该功能的名称。并确保数值和变量名称之间的匹配正确
这是一个示例,但我无法导出到.csv correclty
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)
答案 0 :(得分:1)
使用此
x = list(zip(my_forest.feature_importances_,list of features you are using))
x = pandas.DataFrame(x,columns=["Importance","Feature_Name"])