gpt4 book ai didi

python - 从随机森林导出特征重要性到 csv

转载 作者:行者123 更新时间:2023-11-28 17:26:51 26 4
gpt4 key购买 nike

您好,我想创建一个包含 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)

最佳答案

使用这个

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

关于python - 从随机森林导出特征重要性到 csv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38185014/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com