当前位置:   article > 正文

python重要性_基于Python的随机森林特征重要性图

python绘制随机森林重要度排序条形图

我正在使用python中的RandomForestRegressor,我想创建一个图表来说明特性重要性的排名。这是我使用的代码:from sklearn.ensemble import RandomForestRegressor

MT= pd.read_csv("MT_reduced.csv")

df = MT.reset_index(drop = False)

columns2 = df.columns.tolist()

# Filter the columns to remove ones we don't want.

columns2 = [c for c in columns2 if c not in["Violent_crime_rate","Change_Property_crime_rate","State","Year"]]

# Store the variable we'll be predicting on.

target = "Property_crime_rate"

# Let’s randomly split our data with 80% as the train set and 20% as the test set:

# Generate the training set. Set random_state to be able to replicate results.

train2 = df.sample(frac=0.8, random_state=1)

#exclude all obs with matching index

test2 = df.loc[~df.index.isin(train2.index)]

print(train2.shape) #need to have same num

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/423768
推荐阅读
相关标签
  

闽ICP备14008679号