赞
踩
我正在使用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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。