【发布时间】:2018-07-16 15:46:34
【问题描述】:
我想在散景中绘制RandomForestClassifier() 中的顶部 n 特征,而不在 y 变量中明确指定列名。
-
所以首先,它可以直接从随机分类器的顶部特征中获取列名和值,而不是在变量 y 中输入列名。
y = df['new'] x = df.drop('new', axis=1) rf = RandomForestClassifier() rf.fit(x,y) #Extract the top feature from above and plot in bokeh source = ColumnDataSource(df) p1 = figure(y_range=(0, 10)) # below I would like it to use the top feature in RandomClassifier # instead of explicitly writing the column name, horsePower, # from the top features column p1.line( x = 'x', y = 'horsePower', source=source, legend = 'Car Blue', color = 'Blue' ) -
我们可以构建一个
for循环来绘制散景中的 n 个顶部特征,而不是仅指定第一个特征或第二个特征。我想它是接近这个的东西for i in range(5): p.line(x = 'x', y = ???? , source=source,) #top feature in randomClassifier p.circle(x = 'x', y = ???? , source=source, size = 10) row = [p] output_file('TopFeatures') show(p)
我已经从模型的 RandomForestClassifier 中提取了前 15 个特征,并使用
打印了前 15 个 new_rf = pd.Series(rf.feature_importances_,index=x.columns).sort_values(ascending=False)
print(new_rf[:15])
【问题讨论】: